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

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

Issue 19997003: Implement more restrictive checking of typedefs illegally referring to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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.h ('k') | tests/language/function_type_alias6_test.dart » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 test2 = test2.SuperClass(); 1656 test2 = test2.SuperClass();
1657 if (!test2.IsNull()) { 1657 if (!test2.IsNull()) {
1658 test2 = test2.SuperClass(); 1658 test2 = test2.SuperClass();
1659 } 1659 }
1660 } 1660 }
1661 // No cycles. 1661 // No cycles.
1662 return true; 1662 return true;
1663 } 1663 }
1664 1664
1665 1665
1666 // Helper function called by IsAliasCycleFree.
1667 bool ClassFinalizer::IsParameterTypeCycleFree(
1668 const Class& cls,
1669 const AbstractType& type,
1670 GrowableArray<intptr_t>* visited) {
1671 ASSERT(visited != NULL);
1672 ResolveType(cls, type, kCanonicalize);
1673 if (type.IsType() && !type.IsMalformed()) {
1674 const Class& type_class = Class::Handle(type.type_class());
1675 if (!type_class.is_type_finalized() &&
1676 type_class.IsSignatureClass() &&
1677 !IsAliasCycleFree(type_class, visited)) {
1678 return false;
1679 }
1680 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle(
1681 type.arguments());
1682 if (!type_args.IsNull()) {
1683 AbstractType& type_arg = AbstractType::Handle();
1684 for (intptr_t i = 0; i < type_args.Length(); i++) {
1685 type_arg = type_args.TypeAt(i);
1686 if (!IsParameterTypeCycleFree(cls, type_arg, visited)) {
1687 return false;
1688 }
1689 }
1690 }
1691 }
1692 return true;
1693 }
1694
1695
1666 // Returns false if the function type alias illegally refers to itself. 1696 // Returns false if the function type alias illegally refers to itself.
1667 bool ClassFinalizer::IsAliasCycleFree(const Class& cls, 1697 bool ClassFinalizer::IsAliasCycleFree(const Class& cls,
1668 GrowableArray<intptr_t>* visited) { 1698 GrowableArray<intptr_t>* visited) {
1669 ASSERT(cls.IsSignatureClass()); 1699 ASSERT(cls.IsSignatureClass());
1670 ASSERT(!cls.is_type_finalized()); 1700 ASSERT(!cls.is_type_finalized());
1671 ASSERT(visited != NULL); 1701 ASSERT(visited != NULL);
1672 const intptr_t cls_index = cls.id(); 1702 const intptr_t cls_index = cls.id();
1673 for (int i = 0; i < visited->length(); i++) { 1703 for (int i = 0; i < visited->length(); i++) {
1674 if ((*visited)[i] == cls_index) { 1704 if ((*visited)[i] == cls_index) {
1675 // We have already visited alias 'cls'. We found a cycle. 1705 // We have already visited alias 'cls'. We found a cycle.
1676 return false; 1706 return false;
1677 } 1707 }
1678 } 1708 }
1679 1709
1680 // Visit the result type and parameter types of this signature type. 1710 // Visit the result type and parameter types of this signature type.
1681 visited->Add(cls.id()); 1711 visited->Add(cls.id());
1682 const Function& function = Function::Handle(cls.signature_function()); 1712 const Function& function = Function::Handle(cls.signature_function());
1683 // Check class of result type. 1713 // Check class of result type.
1684 AbstractType& type = AbstractType::Handle(function.result_type()); 1714 AbstractType& type = AbstractType::Handle(function.result_type());
1685 ResolveType(cls, type, kCanonicalize); 1715 if (!IsParameterTypeCycleFree(cls, type, visited)) {
1686 if (type.IsType() && !type.IsMalformed()) { 1716 return false;
1687 const Class& type_class = Class::Handle(type.type_class());
1688 if (!type_class.is_type_finalized() &&
1689 type_class.IsSignatureClass() &&
1690 !IsAliasCycleFree(type_class, visited)) {
1691 return false;
1692 }
1693 } 1717 }
1694 // Check classes of formal parameter types. 1718 // Check classes of formal parameter types.
1695 const intptr_t num_parameters = function.NumParameters(); 1719 const intptr_t num_parameters = function.NumParameters();
1696 for (intptr_t i = 0; i < num_parameters; i++) { 1720 for (intptr_t i = 0; i < num_parameters; i++) {
1697 type = function.ParameterTypeAt(i); 1721 type = function.ParameterTypeAt(i);
1698 ResolveType(cls, type, kCanonicalize); 1722 if (!IsParameterTypeCycleFree(cls, type, visited)) {
1699 if (type.IsType() && !type.IsMalformed()) { 1723 return false;
1700 const Class& type_class = Class::Handle(type.type_class());
1701 if (!type_class.is_type_finalized() &&
1702 type_class.IsSignatureClass() &&
1703 !IsAliasCycleFree(type_class, visited)) {
1704 return false;
1705 }
1706 } 1724 }
1707 } 1725 }
1708 visited->RemoveLast(); 1726 visited->RemoveLast();
1709 return true; 1727 return true;
1710 } 1728 }
1711 1729
1712 1730
1713 void ClassFinalizer::CollectTypeArguments(const Class& cls, 1731 void ClassFinalizer::CollectTypeArguments(const Class& cls,
1714 const Type& type, 1732 const Type& type,
1715 const GrowableObjectArray& collected_args) { 1733 const GrowableObjectArray& collected_args) {
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 expected_name ^= String::New("_offset"); 2187 expected_name ^= String::New("_offset");
2170 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 2188 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
2171 field ^= fields_array.At(2); 2189 field ^= fields_array.At(2);
2172 ASSERT(field.Offset() == TypedDataView::length_offset()); 2190 ASSERT(field.Offset() == TypedDataView::length_offset());
2173 name ^= field.name(); 2191 name ^= field.name();
2174 ASSERT(name.Equals("length")); 2192 ASSERT(name.Equals("length"));
2175 #endif 2193 #endif
2176 } 2194 }
2177 2195
2178 } // namespace dart 2196 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | tests/language/function_type_alias6_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698