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 2020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 if (function.IsImplicitStaticClosureFunction()) { | 2031 if (function.IsImplicitStaticClosureFunction()) { |
2032 const Instance& closure = | 2032 const Instance& closure = |
2033 Instance::ZoneHandle(function.ImplicitStaticClosure()); | 2033 Instance::ZoneHandle(function.ImplicitStaticClosure()); |
2034 ReturnDefinition(new ConstantInstr(closure)); | 2034 ReturnDefinition(new ConstantInstr(closure)); |
2035 return; | 2035 return; |
2036 } | 2036 } |
2037 if (function.IsNonImplicitClosureFunction()) { | 2037 if (function.IsNonImplicitClosureFunction()) { |
2038 // The context scope may have already been set by the non-optimizing | 2038 // The context scope may have already been set by the non-optimizing |
2039 // compiler. If it was not, set it here. | 2039 // compiler. If it was not, set it here. |
2040 if (function.context_scope() == ContextScope::null()) { | 2040 if (function.context_scope() == ContextScope::null()) { |
2041 // TODO(regis): Why are we not doing this in the parser? | |
2042 const ContextScope& context_scope = ContextScope::ZoneHandle( | 2041 const ContextScope& context_scope = ContextScope::ZoneHandle( |
2043 node->scope()->PreserveOuterScope(owner()->context_level())); | 2042 node->scope()->PreserveOuterScope(owner()->context_level())); |
2044 ASSERT(!function.HasCode()); | 2043 ASSERT(!function.HasCode()); |
2045 ASSERT(function.context_scope() == ContextScope::null()); | 2044 ASSERT(function.context_scope() == ContextScope::null()); |
2046 function.set_context_scope(context_scope); | 2045 function.set_context_scope(context_scope); |
| 2046 const Class& cls = Class::Handle( |
| 2047 owner()->parsed_function()->function().Owner()); |
| 2048 // The closure is now properly setup, add it to the lookup table. |
| 2049 #if DEBUG |
| 2050 const Function& found_func = Function::Handle( |
| 2051 cls.LookupClosureFunction(function.token_pos())); |
| 2052 ASSERT(found_func.IsNull() || |
| 2053 (found_func.token_pos() != function.token_pos()) || |
| 2054 // TODO(hausner): The following check should not be necessary. |
| 2055 // Since we only lookup based on the token_pos we can get |
| 2056 // duplicate entries due to closurized and non-closurized parent |
| 2057 // functions (see Parser::ParseFunctionStatement). |
| 2058 // We need two ways to lookup in this cache: One way to cache the |
| 2059 // appropriate closure function and one way to find the functions |
| 2060 // while debugging (we might need to set breakpoints in multiple |
| 2061 // different function for a single token index.) |
| 2062 (found_func.parent_function() != function.parent_function())); |
| 2063 #endif // DEBUG |
| 2064 cls.AddClosureFunction(function); |
2047 } | 2065 } |
2048 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 2066 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
2049 new ZoneGrowableArray<PushArgumentInstr*>(2); | 2067 new ZoneGrowableArray<PushArgumentInstr*>(2); |
2050 ASSERT(function.context_scope() != ContextScope::null()); | 2068 ASSERT(function.context_scope() != ContextScope::null()); |
2051 | 2069 |
2052 // The function type of a closure may have type arguments. In that case, | 2070 // The function type of a closure may have type arguments. In that case, |
2053 // pass the type arguments of the instantiator. | 2071 // pass the type arguments of the instantiator. |
2054 const Class& cls = Class::ZoneHandle(function.signature_class()); | 2072 const Class& cls = Class::ZoneHandle(function.signature_class()); |
2055 ASSERT(!cls.IsNull()); | 2073 ASSERT(!cls.IsNull()); |
2056 const bool requires_type_arguments = cls.HasTypeArguments(); | 2074 const bool requires_type_arguments = cls.HasTypeArguments(); |
(...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3808 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3826 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
3809 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3827 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
3810 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3828 OS::SNPrint(chars, len, kFormat, function_name, reason); |
3811 const Error& error = Error::Handle( | 3829 const Error& error = Error::Handle( |
3812 LanguageError::New(String::Handle(String::New(chars)))); | 3830 LanguageError::New(String::Handle(String::New(chars)))); |
3813 Isolate::Current()->long_jump_base()->Jump(1, error); | 3831 Isolate::Current()->long_jump_base()->Jump(1, error); |
3814 } | 3832 } |
3815 | 3833 |
3816 | 3834 |
3817 } // namespace dart | 3835 } // namespace dart |
OLD | NEW |