Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Side by Side Diff: runtime/lib/mirrors.cc

Issue 910313002: Rename IsConstructor to IsGenerativeConstructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/class_finalizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "lib/mirrors.h" 5 #include "lib/mirrors.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bootstrap_natives.h" 8 #include "vm/bootstrap_natives.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 args.SetAt(5, array); 64 args.SetAt(5, array);
65 } 65 }
66 66
67 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); 67 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args);
68 UNREACHABLE(); 68 UNREACHABLE();
69 } 69 }
70 70
71 71
72 static void EnsureConstructorsAreCompiled(const Function& func) { 72 static void EnsureConstructorsAreCompiled(const Function& func) {
73 // Only generative constructors can have initializing formals. 73 // Only generative constructors can have initializing formals.
74 if (!func.IsConstructor()) return; 74 if (!func.IsGenerativeConstructor()) return;
75 75
76 Isolate* isolate = Isolate::Current(); 76 Isolate* isolate = Isolate::Current();
77 const Class& cls = Class::Handle(isolate, func.Owner()); 77 const Class& cls = Class::Handle(isolate, func.Owner());
78 const Error& error = Error::Handle( 78 const Error& error = Error::Handle(
79 isolate, cls.EnsureIsFinalized(Isolate::Current())); 79 isolate, cls.EnsureIsFinalized(Isolate::Current()));
80 if (!error.IsNull()) { 80 if (!error.IsNull()) {
81 Exceptions::PropagateError(error); 81 Exceptions::PropagateError(error);
82 UNREACHABLE(); 82 UNREACHABLE();
83 } 83 }
84 if (!func.HasCode()) { 84 if (!func.HasCode()) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 args.SetAt(2, owner_mirror); 250 args.SetAt(2, owner_mirror);
251 args.SetAt(3, Bool::Get(func.is_static())); 251 args.SetAt(3, Bool::Get(func.is_static()));
252 args.SetAt(4, Bool::Get(func.is_abstract())); 252 args.SetAt(4, Bool::Get(func.is_abstract()));
253 args.SetAt(5, Bool::Get(func.IsGetterFunction())); 253 args.SetAt(5, Bool::Get(func.IsGetterFunction()));
254 args.SetAt(6, Bool::Get(func.IsSetterFunction())); 254 args.SetAt(6, Bool::Get(func.IsSetterFunction()));
255 255
256 bool isConstructor = (func.kind() == RawFunction::kConstructor); 256 bool isConstructor = (func.kind() == RawFunction::kConstructor);
257 args.SetAt(7, Bool::Get(isConstructor)); 257 args.SetAt(7, Bool::Get(isConstructor));
258 args.SetAt(8, Bool::Get(isConstructor && func.is_const())); 258 args.SetAt(8, Bool::Get(isConstructor && func.is_const()));
259 args.SetAt(9, Bool::Get(isConstructor && func.IsConstructor())); 259 args.SetAt(9, Bool::Get(isConstructor && func.IsGenerativeConstructor()));
260 args.SetAt(10, Bool::Get(isConstructor && func.is_redirecting())); 260 args.SetAt(10, Bool::Get(isConstructor && func.is_redirecting()));
261 args.SetAt(11, Bool::Get(isConstructor && func.IsFactory())); 261 args.SetAt(11, Bool::Get(isConstructor && func.IsFactory()));
262 262
263 return CreateMirror(Symbols::_LocalMethodMirror(), args); 263 return CreateMirror(Symbols::_LocalMethodMirror(), args);
264 } 264 }
265 265
266 266
267 static RawInstance* CreateVariableMirror(const Field& field, 267 static RawInstance* CreateVariableMirror(const Field& field,
268 const Instance& owner_mirror) { 268 const Instance& owner_mirror) {
269 const MirrorReference& field_ref = 269 const MirrorReference& field_ref =
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 String::Handle(String::Concat(klass_name, Symbols::Dot())); 1533 String::Handle(String::Concat(klass_name, Symbols::Dot()));
1534 if (!constructor_name.IsNull()) { 1534 if (!constructor_name.IsNull()) {
1535 internal_constructor_name = 1535 internal_constructor_name =
1536 String::Concat(internal_constructor_name, constructor_name); 1536 String::Concat(internal_constructor_name, constructor_name);
1537 } 1537 }
1538 1538
1539 Function& lookup_constructor = Function::Handle( 1539 Function& lookup_constructor = Function::Handle(
1540 klass.LookupFunction(internal_constructor_name)); 1540 klass.LookupFunction(internal_constructor_name));
1541 1541
1542 if (lookup_constructor.IsNull() || 1542 if (lookup_constructor.IsNull() ||
1543 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || 1543 (lookup_constructor.kind() != RawFunction::kConstructor) ||
1544 !lookup_constructor.is_reflectable()) { 1544 !lookup_constructor.is_reflectable()) {
1545 // Pretend we didn't find the constructor at all when the arity is wrong 1545 // Pretend we didn't find the constructor at all when the arity is wrong
1546 // so as to produce the same NoSuchMethodError as the non-reflective case. 1546 // so as to produce the same NoSuchMethodError as the non-reflective case.
1547 lookup_constructor = Function::null(); 1547 lookup_constructor = Function::null();
1548 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1548 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1549 internal_constructor_name, 1549 internal_constructor_name,
1550 lookup_constructor, 1550 lookup_constructor,
1551 Object::null_array(), 1551 Object::null_array(),
1552 InvocationMirror::kConstructor, 1552 InvocationMirror::kConstructor,
1553 InvocationMirror::kMethod); 1553 InvocationMirror::kMethod);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 type = redirect_type.raw(); 1595 type = redirect_type.raw();
1596 type_arguments = redirect_type.arguments(); 1596 type_arguments = redirect_type.arguments();
1597 1597
1598 redirected_constructor = lookup_constructor.RedirectionTarget(); 1598 redirected_constructor = lookup_constructor.RedirectionTarget();
1599 ASSERT(!redirected_constructor.IsNull()); 1599 ASSERT(!redirected_constructor.IsNull());
1600 redirected_klass = type.type_class(); 1600 redirected_klass = type.type_class();
1601 } 1601 }
1602 1602
1603 const intptr_t num_explicit_args = explicit_args.Length(); 1603 const intptr_t num_explicit_args = explicit_args.Length();
1604 const intptr_t num_implicit_args = 1604 const intptr_t num_implicit_args =
1605 redirected_constructor.IsConstructor() ? 2 : 1; 1605 redirected_constructor.IsGenerativeConstructor() ? 2 : 1;
1606 const Array& args = 1606 const Array& args =
1607 Array::Handle(Array::New(num_implicit_args + num_explicit_args)); 1607 Array::Handle(Array::New(num_implicit_args + num_explicit_args));
1608 1608
1609 // Copy over the explicit arguments. 1609 // Copy over the explicit arguments.
1610 Object& explicit_argument = Object::Handle(); 1610 Object& explicit_argument = Object::Handle();
1611 for (int i = 0; i < num_explicit_args; i++) { 1611 for (int i = 0; i < num_explicit_args; i++) {
1612 explicit_argument = explicit_args.At(i); 1612 explicit_argument = explicit_args.At(i);
1613 args.SetAt(i + num_implicit_args, explicit_argument); 1613 args.SetAt(i + num_implicit_args, explicit_argument);
1614 } 1614 }
1615 1615
(...skipping 10 matching lines...) Expand all
1626 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1626 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1627 internal_constructor_name, 1627 internal_constructor_name,
1628 redirected_constructor, 1628 redirected_constructor,
1629 Object::null_array(), 1629 Object::null_array(),
1630 InvocationMirror::kConstructor, 1630 InvocationMirror::kConstructor,
1631 InvocationMirror::kMethod); 1631 InvocationMirror::kMethod);
1632 UNREACHABLE(); 1632 UNREACHABLE();
1633 } 1633 }
1634 1634
1635 Instance& new_object = Instance::Handle(); 1635 Instance& new_object = Instance::Handle();
1636 if (redirected_constructor.IsConstructor()) { 1636 if (redirected_constructor.IsGenerativeConstructor()) {
1637 // Constructors get the uninitialized object and a constructor phase. Note 1637 // Constructors get the uninitialized object and a constructor phase. Note
1638 // we have delayed allocation until after the function type and argument 1638 // we have delayed allocation until after the function type and argument
1639 // matching checks. 1639 // matching checks.
1640 new_object = Instance::New(redirected_klass); 1640 new_object = Instance::New(redirected_klass);
1641 if (!type_arguments.IsNull()) { 1641 if (!type_arguments.IsNull()) {
1642 // The type arguments will be null if the class has no type parameters, in 1642 // The type arguments will be null if the class has no type parameters, in
1643 // which case the following call would fail because there is no slot 1643 // which case the following call would fail because there is no slot
1644 // reserved in the object for the type vector. 1644 // reserved in the object for the type vector.
1645 new_object.SetTypeArguments(type_arguments); 1645 new_object.SetTypeArguments(type_arguments);
1646 } 1646 }
(...skipping 10 matching lines...) Expand all
1657 args, 1657 args,
1658 args_descriptor_array)); 1658 args_descriptor_array));
1659 if (result.IsError()) { 1659 if (result.IsError()) {
1660 Exceptions::PropagateError(Error::Cast(result)); 1660 Exceptions::PropagateError(Error::Cast(result));
1661 UNREACHABLE(); 1661 UNREACHABLE();
1662 } 1662 }
1663 1663
1664 // Factories may return null. 1664 // Factories may return null.
1665 ASSERT(result.IsInstance() || result.IsNull()); 1665 ASSERT(result.IsInstance() || result.IsNull());
1666 1666
1667 if (redirected_constructor.IsConstructor()) { 1667 if (redirected_constructor.IsGenerativeConstructor()) {
1668 return new_object.raw(); 1668 return new_object.raw();
1669 } else { 1669 } else {
1670 return result.raw(); 1670 return result.raw();
1671 } 1671 }
1672 } 1672 }
1673 1673
1674 1674
1675 DEFINE_NATIVE_ENTRY(LibraryMirror_invoke, 5) { 1675 DEFINE_NATIVE_ENTRY(LibraryMirror_invoke, 5) {
1676 // Argument 0 is the mirror, which is unused by the native. It exists 1676 // Argument 0 is the mirror, which is unused by the native. It exists
1677 // because this native is an instance method in order to be polymorphic 1677 // because this native is an instance method in order to be polymorphic
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1833 const Function& func = Function::Handle(ref.GetFunctionReferent());
1834 return CreateParameterMirrorList(func, owner); 1834 return CreateParameterMirrorList(func, owner);
1835 } 1835 }
1836 1836
1837 1837
1838 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 2) { 1838 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 2) {
1839 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1839 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1840 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1840 const Function& func = Function::Handle(ref.GetFunctionReferent());
1841 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); 1841 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1842 // We handle constructors in Dart code. 1842 // We handle constructors in Dart code.
1843 ASSERT(!func.IsConstructor()); 1843 ASSERT(!func.IsGenerativeConstructor());
1844 const AbstractType& type = AbstractType::Handle(func.result_type()); 1844 const AbstractType& type = AbstractType::Handle(func.result_type());
1845 return InstantiateType(type, instantiator); 1845 return InstantiateType(type, instantiator);
1846 } 1846 }
1847 1847
1848 1848
1849 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) { 1849 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) {
1850 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1850 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1851 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1851 const Function& func = Function::Handle(ref.GetFunctionReferent());
1852 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { 1852 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) {
1853 // We may need to handle more cases when the restrictions on mixins are 1853 // We may need to handle more cases when the restrictions on mixins are
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 } 1965 }
1966 1966
1967 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 1967 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
1968 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 1968 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
1970 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 1970 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
1971 } 1971 }
1972 1972
1973 1973
1974 } // namespace dart 1974 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/class_finalizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698