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

Side by Side Diff: runtime/vm/object.cc

Issue 10103009: Implement implicit interfaces (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 | « runtime/vm/class_finalizer.cc ('k') | tests/co19/co19-runtime.status » ('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 "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 } 1528 }
1529 // Check for two function types. 1529 // Check for two function types.
1530 if (IsSignatureClass() && other.IsSignatureClass()) { 1530 if (IsSignatureClass() && other.IsSignatureClass()) {
1531 const Function& fun = Function::Handle(signature_function()); 1531 const Function& fun = Function::Handle(signature_function());
1532 const Function& other_fun = Function::Handle(other.signature_function()); 1532 const Function& other_fun = Function::Handle(other.signature_function());
1533 return fun.IsSubtypeOf(type_arguments, 1533 return fun.IsSubtypeOf(type_arguments,
1534 other_fun, 1534 other_fun,
1535 other_type_arguments, 1535 other_type_arguments,
1536 malformed_error); 1536 malformed_error);
1537 } 1537 }
1538 // Check for 'direct super type' in the case of an interface and check for 1538 // Check for 'direct super type' in the case of an interface and check for
regis 2012/04/16 22:14:52 You could clarify the comment: ... in the case of
hausner 2012/04/16 23:19:09 Done.
1539 // transitivity at the same time. 1539 // transitivity at the same time.
1540 if (other.is_interface()) { 1540 Array& interfaces = Array::Handle(this->interfaces());
1541 Array& interfaces = Array::Handle(this->interfaces()); 1541 AbstractType& interface = AbstractType::Handle();
1542 AbstractType& interface = AbstractType::Handle(); 1542 Class& interface_class = Class::Handle();
1543 Class& interface_class = Class::Handle(); 1543 AbstractTypeArguments& interface_args = AbstractTypeArguments::Handle();
1544 AbstractTypeArguments& interface_args = AbstractTypeArguments::Handle(); 1544 for (intptr_t i = 0; i < interfaces.Length(); i++) {
1545 for (intptr_t i = 0; i < interfaces.Length(); i++) { 1545 interface ^= interfaces.At(i);
1546 interface ^= interfaces.At(i); 1546 interface_class = interface.type_class();
1547 interface_class = interface.type_class(); 1547 interface_args = interface.arguments();
1548 interface_args = interface.arguments(); 1548 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) {
1549 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { 1549 // This type class implements an interface that is parameterized with
1550 // This type class implements an interface that is parameterized with 1550 // generic type(s), e.g. it implements List<T>.
1551 // generic type(s), e.g. it implements List<T>. 1551 // The uninstantiated type T must be instantiated using the type
1552 // The uninstantiated type T must be instantiated using the type 1552 // parameters of this type before performing the type test.
1553 // parameters of this type before performing the type test. 1553 // The type arguments of this type that are referred to by the type
1554 // The type arguments of this type that are referred to by the type 1554 // parameters of the interface are at the end of the type vector,
1555 // parameters of the interface are at the end of the type vector, 1555 // after the type arguments of the super type of this type.
1556 // after the type arguments of the super type of this type. 1556 // The index of the type parameters is adjusted upon finalization.
1557 // The index of the type parameters is adjusted upon finalization. 1557 ASSERT(interface.IsFinalized());
1558 ASSERT(interface.IsFinalized()); 1558 interface_args = interface_args.InstantiateFrom(type_arguments);
1559 interface_args = interface_args.InstantiateFrom(type_arguments); 1559 // In checked mode, verify that the instantiated interface type
1560 // In checked mode, verify that the instantiated interface type 1560 // arguments are within the bounds specified by the interface class.
1561 // arguments are within the bounds specified by the interface class. 1561 // Note that the additional bounds check in checked mode may lead to a
1562 // Note that the additional bounds check in checked mode may lead to a 1562 // dynamic type error, but it will never change the result of the type
1563 // dynamic type error, but it will never change the result of the type 1563 // check from true in production mode to false in checked mode.
1564 // check from true in production mode to false in checked mode. 1564 if (FLAG_enable_type_checks && !interface_args.IsNull()) {
1565 if (FLAG_enable_type_checks && !interface_args.IsNull()) { 1565 // Pass type_arguments as bounds instantiator.
1566 // Pass type_arguments as bounds instantiator. 1566 if (!interface_args.IsWithinBoundsOf(interface_class,
1567 if (!interface_args.IsWithinBoundsOf(interface_class, 1567 type_arguments,
1568 type_arguments, 1568 malformed_error)) {
1569 malformed_error)) { 1569 continue;
1570 continue;
1571 }
1572 } 1570 }
1573 } 1571 }
1574 if (interface_class.IsSubtypeOf(interface_args, 1572 }
1575 other, 1573 if (interface_class.IsSubtypeOf(interface_args,
1576 other_type_arguments, 1574 other,
1577 malformed_error)) { 1575 other_type_arguments,
1578 return true; 1576 malformed_error)) {
1579 } 1577 return true;
1580 } 1578 }
1581 } 1579 }
1582 // Check the interface case. 1580 // Check the interface case.
1583 if (is_interface()) { 1581 if (is_interface()) {
1584 // We already checked the case where 'other' is an interface. Now, 'this', 1582 // We already checked the case where 'other' is an interface. Now, 'this',
1585 // an interface, cannot be more specific than a class, except class Object, 1583 // an interface, cannot be more specific than a class, except class Object,
1586 // because although Object is not considered an interface by the vm, it is 1584 // because although Object is not considered an interface by the vm, it is
1587 // one. In other words, all classes implementing this interface also extend 1585 // one. In other words, all classes implementing this interface also extend
1588 // class Object. An interface is also more specific than the DynamicType. 1586 // class Object. An interface is also more specific than the DynamicType.
1589 return (other.IsDynamicClass() || other.IsObjectClass()); 1587 return (other.IsDynamicClass() || other.IsObjectClass());
(...skipping 7540 matching lines...) Expand 10 before | Expand all | Expand 10 after
9130 const String& str = String::Handle(pattern()); 9128 const String& str = String::Handle(pattern());
9131 const char* format = "JSRegExp: pattern=%s flags=%s"; 9129 const char* format = "JSRegExp: pattern=%s flags=%s";
9132 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 9130 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
9133 char* chars = reinterpret_cast<char*>( 9131 char* chars = reinterpret_cast<char*>(
9134 Isolate::Current()->current_zone()->Allocate(len + 1)); 9132 Isolate::Current()->current_zone()->Allocate(len + 1));
9135 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 9133 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
9136 return chars; 9134 return chars;
9137 } 9135 }
9138 9136
9139 } // namespace dart 9137 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698