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 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 if (function.IsImplicitStaticClosureFunction()) { | 2044 if (function.IsImplicitStaticClosureFunction()) { |
2045 const Instance& closure = | 2045 const Instance& closure = |
2046 Instance::ZoneHandle(function.ImplicitStaticClosure()); | 2046 Instance::ZoneHandle(function.ImplicitStaticClosure()); |
2047 ReturnDefinition(new ConstantInstr(closure)); | 2047 ReturnDefinition(new ConstantInstr(closure)); |
2048 return; | 2048 return; |
2049 } | 2049 } |
2050 if (function.IsNonImplicitClosureFunction()) { | 2050 if (function.IsNonImplicitClosureFunction()) { |
2051 // The context scope may have already been set by the non-optimizing | 2051 // The context scope may have already been set by the non-optimizing |
2052 // compiler. If it was not, set it here. | 2052 // compiler. If it was not, set it here. |
2053 if (function.context_scope() == ContextScope::null()) { | 2053 if (function.context_scope() == ContextScope::null()) { |
2054 // TODO(regis): Why are we not doing this in the parser? | |
2055 const ContextScope& context_scope = ContextScope::ZoneHandle( | 2054 const ContextScope& context_scope = ContextScope::ZoneHandle( |
2056 node->scope()->PreserveOuterScope(owner()->context_level())); | 2055 node->scope()->PreserveOuterScope(owner()->context_level())); |
2057 ASSERT(!function.HasCode()); | 2056 ASSERT(!function.HasCode()); |
2058 ASSERT(function.context_scope() == ContextScope::null()); | 2057 ASSERT(function.context_scope() == ContextScope::null()); |
2059 function.set_context_scope(context_scope); | 2058 function.set_context_scope(context_scope); |
| 2059 const Class& cls = Class::Handle( |
| 2060 owner()->parsed_function()->function().Owner()); |
| 2061 // The closure is now properly setup, add it to the lookup table. |
| 2062 #if DEBUG |
| 2063 const Function& found_func = Function::Handle( |
| 2064 cls.LookupClosureFunction(function.token_pos())); |
| 2065 ASSERT(found_func.IsNull() || |
| 2066 (found_func.token_pos() != function.token_pos()) || |
| 2067 // TODO(hausner): The following check should not be necessary. |
| 2068 // Since we only lookup based on the token_pos we can get |
| 2069 // duplicate entries due to closurized and non-closurized parent |
| 2070 // functions (see Parser::ParseFunctionStatement). |
| 2071 // We need two ways to lookup in this cache: One way to cache the |
| 2072 // appropriate closure function and one way to find the functions |
| 2073 // while debugging (we might need to set breakpoints in multiple |
| 2074 // different function for a single token index.) |
| 2075 (found_func.parent_function() != function.parent_function())); |
| 2076 #endif // DEBUG |
| 2077 cls.AddClosureFunction(function); |
2060 } | 2078 } |
2061 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 2079 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
2062 new ZoneGrowableArray<PushArgumentInstr*>(2); | 2080 new ZoneGrowableArray<PushArgumentInstr*>(2); |
2063 ASSERT(function.context_scope() != ContextScope::null()); | 2081 ASSERT(function.context_scope() != ContextScope::null()); |
2064 | 2082 |
2065 // The function type of a closure may have type arguments. In that case, | 2083 // The function type of a closure may have type arguments. In that case, |
2066 // pass the type arguments of the instantiator. | 2084 // pass the type arguments of the instantiator. |
2067 const Class& cls = Class::ZoneHandle(function.signature_class()); | 2085 const Class& cls = Class::ZoneHandle(function.signature_class()); |
2068 ASSERT(!cls.IsNull()); | 2086 ASSERT(!cls.IsNull()); |
2069 const bool requires_type_arguments = cls.HasTypeArguments(); | 2087 const bool requires_type_arguments = cls.HasTypeArguments(); |
(...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3821 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; |
3822 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3840 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
3823 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3841 OS::SNPrint(chars, len, kFormat, function_name, reason); |
3824 const Error& error = Error::Handle( | 3842 const Error& error = Error::Handle( |
3825 LanguageError::New(String::Handle(String::New(chars)))); | 3843 LanguageError::New(String::Handle(String::New(chars)))); |
3826 Isolate::Current()->long_jump_base()->Jump(1, error); | 3844 Isolate::Current()->long_jump_base()->Jump(1, error); |
3827 } | 3845 } |
3828 | 3846 |
3829 | 3847 |
3830 } // namespace dart | 3848 } // namespace dart |
OLD | NEW |