| 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 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 arguments->Add(push_ctor_arg); | 1655 arguments->Add(push_ctor_arg); |
| 1656 | 1656 |
| 1657 BuildPushArguments(*node->arguments(), arguments); | 1657 BuildPushArguments(*node->arguments(), arguments); |
| 1658 Do(new StaticCallInstr(node->token_pos(), | 1658 Do(new StaticCallInstr(node->token_pos(), |
| 1659 node->constructor(), | 1659 node->constructor(), |
| 1660 node->arguments()->names(), | 1660 node->arguments()->names(), |
| 1661 arguments)); | 1661 arguments)); |
| 1662 } | 1662 } |
| 1663 | 1663 |
| 1664 | 1664 |
| 1665 static intptr_t GetResultCidOfConstructor(ConstructorCallNode* node) { |
| 1666 if (node->constructor().IsFactory()) { |
| 1667 const Function& function = node->constructor(); |
| 1668 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| 1669 const Class& function_class = Class::Handle(function.Owner()); |
| 1670 |
| 1671 if (function_class.library() == core_impl_lib.raw()) { |
| 1672 if (function_class.Name() == Symbols::ListImplementation()) { |
| 1673 if (function.name() == Symbols::ListFactory()) { |
| 1674 if (node->arguments()->length() == 0) { |
| 1675 return kGrowableObjectArrayCid; |
| 1676 } else { |
| 1677 ASSERT(node->arguments()->length() == 1); |
| 1678 return kArrayCid; |
| 1679 } |
| 1680 } |
| 1681 } |
| 1682 } |
| 1683 } |
| 1684 return kDynamicCid; // Result cid not known. |
| 1685 } |
| 1686 |
| 1687 |
| 1665 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { | 1688 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 1666 InlineBailout("EffectGraphVisitor::VisitConstructorCallNode"); | 1689 InlineBailout("EffectGraphVisitor::VisitConstructorCallNode"); |
| 1667 if (node->constructor().IsFactory()) { | 1690 if (node->constructor().IsFactory()) { |
| 1668 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 1691 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 1669 new ZoneGrowableArray<PushArgumentInstr*>(); | 1692 new ZoneGrowableArray<PushArgumentInstr*>(); |
| 1670 PushArgumentInstr* push_type_arguments = PushArgument( | 1693 PushArgumentInstr* push_type_arguments = PushArgument( |
| 1671 BuildInstantiatedTypeArguments(node->token_pos(), | 1694 BuildInstantiatedTypeArguments(node->token_pos(), |
| 1672 node->type_arguments())); | 1695 node->type_arguments())); |
| 1673 arguments->Add(push_type_arguments); | 1696 arguments->Add(push_type_arguments); |
| 1674 ASSERT(arguments->length() == 1); | 1697 ASSERT(arguments->length() == 1); |
| 1675 BuildPushArguments(*node->arguments(), arguments); | 1698 BuildPushArguments(*node->arguments(), arguments); |
| 1676 StaticCallInstr* call = | 1699 StaticCallInstr* call = |
| 1677 new StaticCallInstr(node->token_pos(), | 1700 new StaticCallInstr(node->token_pos(), |
| 1678 node->constructor(), | 1701 node->constructor(), |
| 1679 node->arguments()->names(), | 1702 node->arguments()->names(), |
| 1680 arguments); | 1703 arguments); |
| 1704 // List factories return kArrayCid or kGrowableObjectArrayCid. |
| 1705 call->set_result_cid(GetResultCidOfConstructor(node)); |
| 1681 ReturnDefinition(call); | 1706 ReturnDefinition(call); |
| 1682 return; | 1707 return; |
| 1683 } | 1708 } |
| 1684 // t_n contains the allocated and initialized object. | 1709 // t_n contains the allocated and initialized object. |
| 1685 // t_n <- AllocateObject(class) | 1710 // t_n <- AllocateObject(class) |
| 1686 // t_n+1 <- ctor-arg | 1711 // t_n+1 <- ctor-arg |
| 1687 // t_n+2... <- constructor arguments start here | 1712 // t_n+2... <- constructor arguments start here |
| 1688 // StaticCall(constructor, t_n+1, t_n+2, ...) | 1713 // StaticCall(constructor, t_n+1, t_n+2, ...) |
| 1689 // No need to preserve allocated value (simpler than in ValueGraphVisitor). | 1714 // No need to preserve allocated value (simpler than in ValueGraphVisitor). |
| 1690 Value* allocated_value = BuildObjectAllocation(node); | 1715 Value* allocated_value = BuildObjectAllocation(node); |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2652 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 2677 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 2653 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 2678 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 2654 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2679 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2655 const Error& error = Error::Handle( | 2680 const Error& error = Error::Handle( |
| 2656 LanguageError::New(String::Handle(String::New(chars)))); | 2681 LanguageError::New(String::Handle(String::New(chars)))); |
| 2657 Isolate::Current()->long_jump_base()->Jump(1, error); | 2682 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2658 } | 2683 } |
| 2659 | 2684 |
| 2660 | 2685 |
| 2661 } // namespace dart | 2686 } // namespace dart |
| OLD | NEW |