| 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 1650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 arguments->Add(push_ctor_arg); | 1661 arguments->Add(push_ctor_arg); |
| 1662 | 1662 |
| 1663 BuildPushArguments(*node->arguments(), arguments); | 1663 BuildPushArguments(*node->arguments(), arguments); |
| 1664 Do(new StaticCallInstr(node->token_pos(), | 1664 Do(new StaticCallInstr(node->token_pos(), |
| 1665 node->constructor(), | 1665 node->constructor(), |
| 1666 node->arguments()->names(), | 1666 node->arguments()->names(), |
| 1667 arguments)); | 1667 arguments)); |
| 1668 } | 1668 } |
| 1669 | 1669 |
| 1670 | 1670 |
| 1671 static bool IsRecognizedConstructor(const Function& function, |
| 1672 const String& expected) { |
| 1673 const Class& clazz = Class::Handle(function.Owner()); |
| 1674 const Library& lib = Library::Handle(clazz.library()); |
| 1675 |
| 1676 const String& expected_class_name = |
| 1677 String::Handle(lib.PrivateName(expected)); |
| 1678 if (!String::Handle(clazz.Name()).Equals(expected_class_name)) { |
| 1679 return false; |
| 1680 } |
| 1681 |
| 1682 const String& function_name = String::Handle(function.name()); |
| 1683 const String& expected_function_name = String::Handle( |
| 1684 String::Concat(expected_class_name, String::Handle(Symbols::Dot()))); |
| 1685 return function_name.Equals(expected_function_name); |
| 1686 } |
| 1687 |
| 1688 |
| 1671 static intptr_t GetResultCidOfConstructor(ConstructorCallNode* node) { | 1689 static intptr_t GetResultCidOfConstructor(ConstructorCallNode* node) { |
| 1690 const Function& function = node->constructor(); |
| 1691 const Class& function_class = Class::Handle(function.Owner()); |
| 1692 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| 1693 |
| 1694 if (function_class.library() != core_impl_lib.raw()) { |
| 1695 return kDynamicCid; |
| 1696 } |
| 1697 |
| 1672 if (node->constructor().IsFactory()) { | 1698 if (node->constructor().IsFactory()) { |
| 1673 const Function& function = node->constructor(); | 1699 if ((function_class.Name() == Symbols::ListImplementation()) && |
| 1674 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | 1700 (function.name() == Symbols::ListFactory())) { |
| 1675 const Class& function_class = Class::Handle(function.Owner()); | 1701 // If there are no arguments then the result is guaranteed to be a |
| 1676 | 1702 // GrowableObjectArray. However if there is an argument the result |
| 1677 if (function_class.library() == core_impl_lib.raw()) { | 1703 // is not guaranteed to be a fixed size array because the argument |
| 1678 if (function_class.Name() == Symbols::ListImplementation()) { | 1704 // can be null. |
| 1679 if (function.name() == Symbols::ListFactory()) { | 1705 if (node->arguments()->length() == 0) { |
| 1680 if (node->arguments()->length() == 0) { | 1706 return kGrowableObjectArrayCid; |
| 1681 return kGrowableObjectArrayCid; | 1707 } |
| 1682 } else { | 1708 } else { |
| 1683 ASSERT(node->arguments()->length() == 1); | 1709 if (IsRecognizedConstructor(function, |
| 1684 return kArrayCid; | 1710 String::Handle(Symbols::ObjectArray())) && |
| 1685 } | 1711 (node->arguments()->length() == 1)) { |
| 1686 } | 1712 return kArrayCid; |
| 1713 } else if (IsRecognizedConstructor(function, |
| 1714 String::Handle(Symbols::GrowableObjectArray())) && |
| 1715 (node->arguments()->length() == 0)) { |
| 1716 return kGrowableObjectArrayCid; |
| 1687 } | 1717 } |
| 1688 } | 1718 } |
| 1689 } | 1719 } |
| 1690 return kDynamicCid; // Result cid not known. | 1720 return kDynamicCid; // Result cid not known. |
| 1691 } | 1721 } |
| 1692 | 1722 |
| 1693 | 1723 |
| 1694 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { | 1724 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 1695 if (node->constructor().IsFactory()) { | 1725 if (node->constructor().IsFactory()) { |
| 1696 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 1726 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| (...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2816 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 2846 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 2817 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 2847 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 2818 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2848 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2819 const Error& error = Error::Handle( | 2849 const Error& error = Error::Handle( |
| 2820 LanguageError::New(String::Handle(String::New(chars)))); | 2850 LanguageError::New(String::Handle(String::New(chars)))); |
| 2821 Isolate::Current()->long_jump_base()->Jump(1, error); | 2851 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2822 } | 2852 } |
| 2823 | 2853 |
| 2824 | 2854 |
| 2825 } // namespace dart | 2855 } // namespace dart |
| OLD | NEW |