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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/lib/js_helper.dart

Issue 11448009: Represent runtime type information as nested lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor edits. Created 8 years 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
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 library _js_helper; 5 library _js_helper;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 part 'constant_map.dart'; 9 part 'constant_map.dart';
10 part 'native_helper.dart'; 10 part 'native_helper.dart';
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 bool operator ==(other) { 1624 bool operator ==(other) {
1625 if (other is !TypeImpl) return false; 1625 if (other is !TypeImpl) return false;
1626 return typeName == other.typeName; 1626 return typeName == other.typeName;
1627 } 1627 }
1628 } 1628 }
1629 1629
1630 String getClassName(var object) { 1630 String getClassName(var object) {
1631 return JS('String', r'#.constructor.builtin$cls', object); 1631 return JS('String', r'#.constructor.builtin$cls', object);
1632 } 1632 }
1633 1633
1634 String getTypeArgumentAsString(List runtimeType) {
1635 String className = runtimeTypeToString(runtimeType[0]);
1636 if (runtimeType.length = 1) return className;
1637 return '$className<${joinArguments(runtimeType, 1)}>';
1638 }
1639
1640 String runtimeTypeToString(type) {
1641 if (type == null) {
1642 return 'dynamic';
1643 } else if (type is String) {
1644 // A native class. The string is the unique name.
1645 return type;
1646 } else if (isJsArray(type)) {
1647 // A list representing a type with arguments.
1648 return getTypeArgumentAsString(type);
1649 } else {
1650 // A reference to the constructor.
1651 return JS('String', r'#.builtin$cls', type);
1652 }
1653 }
1654
1655 String joinArguments(var types, int startIndex) {
1656 bool firstArgument = true;
1657 StringBuffer buffer = new StringBuffer();
1658 for (int index = startIndex; index < types.length; index++) {
1659 if (firstArgument) {
1660 firstArgument = false;
1661 } else {
1662 buffer. add(', ');
1663 }
1664 var argument = types[index];
1665 buffer.add(runtimeTypeToString(argument));
1666 }
1667 return buffer.toString();
1668 }
1669
1634 String getRuntimeTypeString(var object) { 1670 String getRuntimeTypeString(var object) {
1635 String className = isJsArray(object) ? 'List' : getClassName(object); 1671 String className = isJsArray(object) ? 'List' : getClassName(object);
1636 var typeInfo = JS('var', r'#.builtin$typeInfo', object); 1672 var typeInfo = JS('var', r'#.builtin$typeInfo', object);
1637 if (typeInfo == null) return className; 1673 if (typeInfo == null) return className;
1638 StringBuffer arguments = new StringBuffer(); 1674 return "$className<${joinArguments(typeInfo, 0)}>";
1639 for (var i = 0; i < typeInfo.length; i++) { 1675 }
1640 if (i > 0) { 1676
1641 arguments.add(', '); 1677 bool isSubtype(var s, var t) {
1678 // TODO(karlklose): support suptyping.
kasperl 2012/12/06 09:51:04 suptyping -> subtyping. Maybe extend the comment t
karlklose 2012/12/06 13:30:03 Done.
1679 if (s == null || t == null) return true;
1680 if (!isJsArray(s)) return s == t;
1681 if (JS('var', '#[0]', s) != JS('var', '#[0]', t)) return false;
1682 int len = JS('int', '#.length', s);
1683 for (int i = 1; i < len; i++) {
1684 if (!isSubtype(JS('var', '#[0]', s), JS('var', '#[0]', s))) {
1685 return false;
1642 } 1686 }
1643 var argument = typeInfo[i];
1644 if (argument == null) {
1645 argument = 'dynamic';
1646 }
1647 arguments.add(argument);
1648 } 1687 }
1649 return '$className<$arguments>'; 1688 return true;
1650 } 1689 }
1651 1690
1652 createRuntimeType(String name) => new TypeImpl(name); 1691 createRuntimeType(String name) => new TypeImpl(name);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698