| 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/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 9643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9654 constr, | 9654 constr, |
| 9655 constr_args)); | 9655 constr_args)); |
| 9656 if (result.IsUnhandledException()) { | 9656 if (result.IsUnhandledException()) { |
| 9657 return GenerateRethrow(symbol_pos, result); | 9657 return GenerateRethrow(symbol_pos, result); |
| 9658 } | 9658 } |
| 9659 const Instance& instance = Instance::Cast(result); | 9659 const Instance& instance = Instance::Cast(result); |
| 9660 return new LiteralNode(symbol_pos, Instance::ZoneHandle(instance.raw())); | 9660 return new LiteralNode(symbol_pos, Instance::ZoneHandle(instance.raw())); |
| 9661 } | 9661 } |
| 9662 | 9662 |
| 9663 | 9663 |
| 9664 static const String& BuildConstructorName(const String& type_class_name, | 9664 static String& BuildConstructorName(const String& type_class_name, |
| 9665 const String* named_constructor) { | 9665 const String* named_constructor) { |
| 9666 // By convention, the static function implementing a named constructor 'C' | 9666 // By convention, the static function implementing a named constructor 'C' |
| 9667 // for class 'A' is labeled 'A.C', and the static function implementing the | 9667 // for class 'A' is labeled 'A.C', and the static function implementing the |
| 9668 // unnamed constructor for class 'A' is labeled 'A.'. | 9668 // unnamed constructor for class 'A' is labeled 'A.'. |
| 9669 // This convention prevents users from explicitly calling constructors. | 9669 // This convention prevents users from explicitly calling constructors. |
| 9670 String& constructor_name = | 9670 String& constructor_name = |
| 9671 String::Handle(String::Concat(type_class_name, Symbols::Dot())); | 9671 String::Handle(String::Concat(type_class_name, Symbols::Dot())); |
| 9672 if (named_constructor != NULL) { | 9672 if (named_constructor != NULL) { |
| 9673 constructor_name = String::Concat(constructor_name, *named_constructor); | 9673 constructor_name = String::Concat(constructor_name, *named_constructor); |
| 9674 } | 9674 } |
| 9675 return constructor_name; | 9675 return constructor_name; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9736 if (type.IsMalformed()) { | 9736 if (type.IsMalformed()) { |
| 9737 if (is_const) { | 9737 if (is_const) { |
| 9738 const Error& error = Error::Handle(type.malformed_error()); | 9738 const Error& error = Error::Handle(type.malformed_error()); |
| 9739 ErrorMsg(error); | 9739 ErrorMsg(error); |
| 9740 } | 9740 } |
| 9741 return ThrowTypeError(type_pos, type); | 9741 return ThrowTypeError(type_pos, type); |
| 9742 } | 9742 } |
| 9743 | 9743 |
| 9744 // Resolve the type and optional identifier to a constructor or factory. | 9744 // Resolve the type and optional identifier to a constructor or factory. |
| 9745 Class& type_class = Class::Handle(type.type_class()); | 9745 Class& type_class = Class::Handle(type.type_class()); |
| 9746 const String& type_class_name = String::Handle(type_class.Name()); | 9746 String& type_class_name = String::Handle(type_class.Name()); |
| 9747 AbstractTypeArguments& type_arguments = | 9747 AbstractTypeArguments& type_arguments = |
| 9748 AbstractTypeArguments::ZoneHandle(type.arguments()); | 9748 AbstractTypeArguments::ZoneHandle(type.arguments()); |
| 9749 | 9749 |
| 9750 // A constructor has an implicit 'this' parameter (instance to construct) | 9750 // A constructor has an implicit 'this' parameter (instance to construct) |
| 9751 // and a factory has an implicit 'this' parameter (type_arguments). | 9751 // and a factory has an implicit 'this' parameter (type_arguments). |
| 9752 // A constructor has a second implicit 'phase' parameter. | 9752 // A constructor has a second implicit 'phase' parameter. |
| 9753 intptr_t arguments_length = arguments->length() + 2; | 9753 intptr_t arguments_length = arguments->length() + 2; |
| 9754 | 9754 |
| 9755 // An additional type check of the result of a redirecting factory may be | 9755 // An additional type check of the result of a redirecting factory may be |
| 9756 // required. | 9756 // required. |
| 9757 AbstractType& type_bound = AbstractType::ZoneHandle(); | 9757 AbstractType& type_bound = AbstractType::ZoneHandle(); |
| 9758 | 9758 |
| 9759 // Make sure that an appropriate constructor exists. | 9759 // Make sure that an appropriate constructor exists. |
| 9760 const String& constructor_name = | 9760 String& constructor_name = |
| 9761 BuildConstructorName(type_class_name, named_constructor); | 9761 BuildConstructorName(type_class_name, named_constructor); |
| 9762 Function& constructor = Function::ZoneHandle( | 9762 Function& constructor = Function::ZoneHandle( |
| 9763 type_class.LookupConstructor(constructor_name)); | 9763 type_class.LookupConstructor(constructor_name)); |
| 9764 if (constructor.IsNull()) { | 9764 if (constructor.IsNull()) { |
| 9765 constructor = type_class.LookupFactory(constructor_name); | 9765 constructor = type_class.LookupFactory(constructor_name); |
| 9766 if (constructor.IsNull()) { | 9766 if (constructor.IsNull()) { |
| 9767 const String& external_constructor_name = | 9767 const String& external_constructor_name = |
| 9768 (named_constructor ? constructor_name : type_class_name); | 9768 (named_constructor ? constructor_name : type_class_name); |
| 9769 // Replace the type with a malformed type and compile a throw or report a | 9769 // Replace the type with a malformed type and compile a throw or report a |
| 9770 // compile-time error if the constructor is const. | 9770 // compile-time error if the constructor is const. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9804 ErrorMsg(Error::Handle(redirect_type.malformed_error())); | 9804 ErrorMsg(Error::Handle(redirect_type.malformed_error())); |
| 9805 } | 9805 } |
| 9806 return ThrowTypeError(redirect_type.token_pos(), redirect_type); | 9806 return ThrowTypeError(redirect_type.token_pos(), redirect_type); |
| 9807 } | 9807 } |
| 9808 if (FLAG_enable_type_checks && !redirect_type.IsSubtypeOf(type, NULL)) { | 9808 if (FLAG_enable_type_checks && !redirect_type.IsSubtypeOf(type, NULL)) { |
| 9809 // Additional type checking of the result is necessary. | 9809 // Additional type checking of the result is necessary. |
| 9810 type_bound = type.raw(); | 9810 type_bound = type.raw(); |
| 9811 } | 9811 } |
| 9812 type = redirect_type.raw(); | 9812 type = redirect_type.raw(); |
| 9813 type_class = type.type_class(); | 9813 type_class = type.type_class(); |
| 9814 type_class_name = type_class.Name(); |
| 9814 type_arguments = type.arguments(); | 9815 type_arguments = type.arguments(); |
| 9815 constructor = constructor.RedirectionTarget(); | 9816 constructor = constructor.RedirectionTarget(); |
| 9817 constructor_name = constructor.name(); |
| 9816 ASSERT(!constructor.IsNull()); | 9818 ASSERT(!constructor.IsNull()); |
| 9817 } | 9819 } |
| 9818 if (constructor.IsFactory()) { | 9820 if (constructor.IsFactory()) { |
| 9819 // A factory does not have the implicit 'phase' parameter. | 9821 // A factory does not have the implicit 'phase' parameter. |
| 9820 arguments_length -= 1; | 9822 arguments_length -= 1; |
| 9821 } | 9823 } |
| 9822 } | 9824 } |
| 9823 | 9825 |
| 9824 // It is ok to call a factory method of an abstract class, but it is | 9826 // It is ok to call a factory method of an abstract class, but it is |
| 9825 // a dynamic error to instantiate an abstract class. | 9827 // a dynamic error to instantiate an abstract class. |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10571 void Parser::SkipQualIdent() { | 10573 void Parser::SkipQualIdent() { |
| 10572 ASSERT(IsIdentifier()); | 10574 ASSERT(IsIdentifier()); |
| 10573 ConsumeToken(); | 10575 ConsumeToken(); |
| 10574 if (CurrentToken() == Token::kPERIOD) { | 10576 if (CurrentToken() == Token::kPERIOD) { |
| 10575 ConsumeToken(); // Consume the kPERIOD token. | 10577 ConsumeToken(); // Consume the kPERIOD token. |
| 10576 ExpectIdentifier("identifier expected after '.'"); | 10578 ExpectIdentifier("identifier expected after '.'"); |
| 10577 } | 10579 } |
| 10578 } | 10580 } |
| 10579 | 10581 |
| 10580 } // namespace dart | 10582 } // namespace dart |
| OLD | NEW |