| 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/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 if (function.context_scope() == ContextScope::null()) { | 2185 if (function.context_scope() == ContextScope::null()) { |
| 2186 ASSERT(!is_implicit); | 2186 ASSERT(!is_implicit); |
| 2187 const ContextScope& context_scope = ContextScope::ZoneHandle( | 2187 const ContextScope& context_scope = ContextScope::ZoneHandle( |
| 2188 node->scope()->PreserveOuterScope(owner()->context_level())); | 2188 node->scope()->PreserveOuterScope(owner()->context_level())); |
| 2189 ASSERT(!function.HasCode()); | 2189 ASSERT(!function.HasCode()); |
| 2190 ASSERT(function.context_scope() == ContextScope::null()); | 2190 ASSERT(function.context_scope() == ContextScope::null()); |
| 2191 function.set_context_scope(context_scope); | 2191 function.set_context_scope(context_scope); |
| 2192 const Class& cls = Class::Handle( | 2192 const Class& cls = Class::Handle( |
| 2193 owner()->parsed_function()->function().Owner()); | 2193 owner()->parsed_function()->function().Owner()); |
| 2194 // The closure is now properly setup, add it to the lookup table. | 2194 // The closure is now properly setup, add it to the lookup table. |
| 2195 #if DEBUG | 2195 // It is possible that the compiler creates more than one function |
| 2196 // object for the same closure, e.g. when inlining nodes from |
| 2197 // finally clauses. If we already have a function object for the |
| 2198 // same closure, do not add a second one. We compare the origin |
| 2199 // class, token position, and parent function to detect duplicates. |
| 2200 // Note that we can have two different closure object for the same |
| 2201 // source text represntation of the closure: one with a non-closurized |
| 2202 // parent, and one with a closurized parent function. |
| 2203 |
| 2196 const Function& found_func = Function::Handle( | 2204 const Function& found_func = Function::Handle( |
| 2197 cls.LookupClosureFunction(function.token_pos())); | 2205 cls.LookupClosureFunction(function.token_pos())); |
| 2198 ASSERT(found_func.IsNull() || | 2206 |
| 2199 (found_func.token_pos() != function.token_pos()) || | 2207 if (found_func.IsNull() || |
| 2200 // TODO(hausner): The following check should not be necessary. | 2208 (found_func.token_pos() != function.token_pos()) || |
| 2201 // Since we only lookup based on the token_pos we can get | 2209 (found_func.script() != function.script()) || |
| 2202 // duplicate entries due to closurized and non-closurized parent | 2210 (found_func.parent_function() != function.parent_function())) { |
| 2203 // functions (see Parser::ParseFunctionStatement). | 2211 cls.AddClosureFunction(function); |
| 2204 // We need two ways to lookup in this cache: One way to cache the | 2212 } |
| 2205 // appropriate closure function and one way to find the functions | |
| 2206 // while debugging (we might need to set breakpoints in multiple | |
| 2207 // different function for a single token index.) | |
| 2208 (found_func.parent_function() != function.parent_function())); | |
| 2209 #endif // DEBUG | |
| 2210 cls.AddClosureFunction(function); | |
| 2211 } | 2213 } |
| 2212 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 2214 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 2213 new ZoneGrowableArray<PushArgumentInstr*>(1); | 2215 new ZoneGrowableArray<PushArgumentInstr*>(1); |
| 2214 ASSERT(function.context_scope() != ContextScope::null()); | 2216 ASSERT(function.context_scope() != ContextScope::null()); |
| 2215 | 2217 |
| 2216 // The function type of a closure may have type arguments. In that case, | 2218 // The function type of a closure may have type arguments. In that case, |
| 2217 // pass the type arguments of the instantiator. | 2219 // pass the type arguments of the instantiator. |
| 2218 const Class& cls = Class::ZoneHandle(function.signature_class()); | 2220 const Class& cls = Class::ZoneHandle(function.signature_class()); |
| 2219 ASSERT(!cls.IsNull()); | 2221 ASSERT(!cls.IsNull()); |
| 2220 const bool requires_type_arguments = cls.NumTypeArguments() > 0; | 2222 const bool requires_type_arguments = cls.NumTypeArguments() > 0; |
| (...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3856 function.token_pos(), | 3858 function.token_pos(), |
| 3857 LanguageError::kError, | 3859 LanguageError::kError, |
| 3858 Heap::kNew, | 3860 Heap::kNew, |
| 3859 "FlowGraphBuilder Bailout: %s %s", | 3861 "FlowGraphBuilder Bailout: %s %s", |
| 3860 String::Handle(function.name()).ToCString(), | 3862 String::Handle(function.name()).ToCString(), |
| 3861 reason)); | 3863 reason)); |
| 3862 Isolate::Current()->long_jump_base()->Jump(1, error); | 3864 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3863 } | 3865 } |
| 3864 | 3866 |
| 3865 } // namespace dart | 3867 } // namespace dart |
| OLD | NEW |