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

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 922023002: Implement DeclarationMirror.location for all but ParameterMirrors. (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 | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('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 // VM-specific implementation of the dart:mirrors library. 5 // VM-specific implementation of the dart:mirrors library.
6 6
7 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; 7 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView;
8 8
9 final emptyList = new UnmodifiableListView([]); 9 final emptyList = new UnmodifiableListView([]);
10 final emptyMap = new UnmodifiableMapView({}); 10 final emptyMap = new UnmodifiableMapView({});
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 buf.write('}'); 73 buf.write('}');
74 } 74 }
75 if (found_optional_positional) { 75 if (found_optional_positional) {
76 buf.write(']'); 76 buf.write(']');
77 } 77 }
78 buf.write(') -> '); 78 buf.write(') -> ');
79 buf.write(_n(returnType.qualifiedName)); 79 buf.write(_n(returnType.qualifiedName));
80 return buf.toString(); 80 return buf.toString();
81 } 81 }
82 82
83 SourceLocation _location(reflectee)
84 native "DeclarationMirror_location";
85
83 List _metadata(reflectee) 86 List _metadata(reflectee)
84 native 'DeclarationMirror_metadata'; 87 native 'DeclarationMirror_metadata';
85 88
86 bool _subtypeTest(Type a, Type b) 89 bool _subtypeTest(Type a, Type b)
87 native 'TypeMirror_subtypeTest'; 90 native 'TypeMirror_subtypeTest';
88 91
89 bool _moreSpecificTest(Type a, Type b) 92 bool _moreSpecificTest(Type a, Type b)
90 native 'TypeMirror_moreSpecificTest'; 93 native 'TypeMirror_moreSpecificTest';
91 94
92 class _AccessorCacheAssociation { 95 class _AccessorCacheAssociation {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName); 321 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName);
319 Symbol get constructorName => const Symbol(''); 322 Symbol get constructorName => const Symbol('');
320 323
321 TypeMirror get returnType => _target.type; 324 TypeMirror get returnType => _target.type;
322 List<ParameterMirror> get parameters { 325 List<ParameterMirror> get parameters {
323 if (isGetter) return emptyList; 326 if (isGetter) return emptyList;
324 return new UnmodifiableListView( 327 return new UnmodifiableListView(
325 [new _SyntheticSetterParameter(this, this._target)]); 328 [new _SyntheticSetterParameter(this, this._target)]);
326 } 329 }
327 330
331 SourceLocation get location => null;
328 List<InstanceMirror> get metadata => emptyList; 332 List<InstanceMirror> get metadata => emptyList;
329 String get source => null; 333 String get source => null;
330 SourceLocation get location => null;
331 } 334 }
332 335
333 class _SyntheticSetterParameter implements ParameterMirror { 336 class _SyntheticSetterParameter implements ParameterMirror {
334 final DeclarationMirror owner; 337 final DeclarationMirror owner;
335 final VariableMirror _target; 338 final VariableMirror _target;
336 339
337 _SyntheticSetterParameter(this.owner, this._target); 340 _SyntheticSetterParameter(this.owner, this._target);
338 341
339 Symbol get simpleName => _target.simpleName; 342 Symbol get simpleName => _target.simpleName;
340 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName); 343 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName);
341 TypeMirror get type => _target.type; 344 TypeMirror get type => _target.type;
342 345
343 bool get isOptional => false; 346 bool get isOptional => false;
344 bool get isNamed => false; 347 bool get isNamed => false;
345 bool get isStatic => false; 348 bool get isStatic => false;
346 bool get isTopLevel => false; 349 bool get isTopLevel => false;
347 bool get isConst => false; 350 bool get isConst => false;
348 bool get isFinal => true; 351 bool get isFinal => true;
349 bool get isPrivate => false; 352 bool get isPrivate => false;
350 bool get hasDefaultValue => false; 353 bool get hasDefaultValue => false;
351 InstanceMirror get defaultValue => null; 354 InstanceMirror get defaultValue => null;
355 SourceLocation get location => null;
352 List<InstanceMirror> get metadata => emptyList; 356 List<InstanceMirror> get metadata => emptyList;
353 SourceLocation get location => throw new UnimplementedError();
354 } 357 }
355 358
356 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { 359 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror {
357 final _reflectee; // May be a MirrorReference or an ordinary object. 360 final _reflectee; // May be a MirrorReference or an ordinary object.
358 361
359 _LocalObjectMirror(this._reflectee); 362 _LocalObjectMirror(this._reflectee);
360 363
361 InstanceMirror invoke(Symbol memberName, 364 InstanceMirror invoke(Symbol memberName,
362 List positionalArguments, 365 List positionalArguments,
363 [Map<Symbol, dynamic> namedArguments]) { 366 [Map<Symbol, dynamic> namedArguments]) {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 _owner = _library(_reflectee); 633 _owner = _library(_reflectee);
631 } 634 }
632 return _owner; 635 return _owner;
633 } 636 }
634 637
635 bool get isPrivate => _n(simpleName).startsWith('_'); 638 bool get isPrivate => _n(simpleName).startsWith('_');
636 639
637 final bool isTopLevel = true; 640 final bool isTopLevel = true;
638 641
639 SourceLocation get location { 642 SourceLocation get location {
640 throw new UnimplementedError('ClassMirror.location is not implemented'); 643 return _location(_reflectee);
641 } 644 }
642 645
643 ClassMirror _trueSuperclassField; 646 ClassMirror _trueSuperclassField;
644 ClassMirror get _trueSuperclass { 647 ClassMirror get _trueSuperclass {
645 if (_trueSuperclassField == null) { 648 if (_trueSuperclassField == null) {
646 Type supertype = isOriginalDeclaration 649 Type supertype = isOriginalDeclaration
647 ? _supertype(_reflectedType) 650 ? _supertype(_reflectedType)
648 : _supertypeInstantiated(_reflectedType); 651 : _supertypeInstantiated(_reflectedType);
649 if (supertype == null) { 652 if (supertype == null) {
650 // Object has no superclass. 653 // Object has no superclass.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 Symbol _qualifiedName = null; 1040 Symbol _qualifiedName = null;
1038 Symbol get qualifiedName { 1041 Symbol get qualifiedName {
1039 if (_qualifiedName == null) { 1042 if (_qualifiedName == null) {
1040 _qualifiedName = _computeQualifiedName(owner, simpleName); 1043 _qualifiedName = _computeQualifiedName(owner, simpleName);
1041 } 1044 }
1042 return _qualifiedName; 1045 return _qualifiedName;
1043 } 1046 }
1044 1047
1045 bool get isPrivate => _n(simpleName).startsWith('_'); 1048 bool get isPrivate => _n(simpleName).startsWith('_');
1046 1049
1050 SourceLocation get location {
1051 return _location(_reflectee);
1052 }
1053
1047 List<InstanceMirror> get metadata { 1054 List<InstanceMirror> get metadata {
1048 // Get the metadata objects, convert them into InstanceMirrors using 1055 // Get the metadata objects, convert them into InstanceMirrors using
1049 // reflect() and then make them into a Dart list. 1056 // reflect() and then make them into a Dart list.
1050 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); 1057 return new UnmodifiableListView(_metadata(_reflectee).map(reflect));
1051 } 1058 }
1052 1059
1053 bool operator ==(other) { 1060 bool operator ==(other) {
1054 return this.runtimeType == other.runtimeType && 1061 return this.runtimeType == other.runtimeType &&
1055 this._reflectee == other._reflectee; 1062 this._reflectee == other._reflectee;
1056 } 1063 }
(...skipping 12 matching lines...) Expand all
1069 DeclarationMirror get owner { 1076 DeclarationMirror get owner {
1070 if (_owner == null) { 1077 if (_owner == null) {
1071 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration; 1078 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration;
1072 } 1079 }
1073 return _owner; 1080 return _owner;
1074 } 1081 }
1075 1082
1076 bool get isStatic => false; 1083 bool get isStatic => false;
1077 bool get isTopLevel => false; 1084 bool get isTopLevel => false;
1078 1085
1079 SourceLocation get location {
1080 throw new UnimplementedError(
1081 'TypeVariableMirror.location is not implemented');
1082 }
1083
1084 TypeMirror _upperBound = null; 1086 TypeMirror _upperBound = null;
1085 TypeMirror get upperBound { 1087 TypeMirror get upperBound {
1086 if (_upperBound == null) { 1088 if (_upperBound == null) {
1087 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); 1089 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee));
1088 } 1090 }
1089 return _upperBound; 1091 return _upperBound;
1090 } 1092 }
1091 1093
1092 bool get hasReflectedType => false; 1094 bool get hasReflectedType => false;
1093 Type get reflectedType { 1095 Type get reflectedType {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 bool get isTopLevel => true; 1150 bool get isTopLevel => true;
1149 1151
1150 DeclarationMirror _owner; 1152 DeclarationMirror _owner;
1151 DeclarationMirror get owner { 1153 DeclarationMirror get owner {
1152 if (_owner == null) { 1154 if (_owner == null) {
1153 _owner = _LocalClassMirror._library(_reflectee); 1155 _owner = _LocalClassMirror._library(_reflectee);
1154 } 1156 }
1155 return _owner; 1157 return _owner;
1156 } 1158 }
1157 1159
1158 SourceLocation get location {
1159 throw new UnimplementedError('TypedefMirror.location is not implemented');
1160 }
1161
1162 TypeMirror _referent = null; 1160 TypeMirror _referent = null;
1163 TypeMirror get referent { 1161 TypeMirror get referent {
1164 if (_referent == null) { 1162 if (_referent == null) {
1165 _referent = _nativeReferent(_reflectedType); 1163 _referent = _nativeReferent(_reflectedType);
1166 _referent._instantiator = _reflectedType; 1164 _referent._instantiator = _reflectedType;
1167 } 1165 }
1168 return _referent; 1166 return _referent;
1169 } 1167 }
1170 1168
1171 bool get hasReflectedType => !_isGenericDeclaration; 1169 bool get hasReflectedType => !_isGenericDeclaration;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 // The simple name and the qualified name are the same for a library. 1255 // The simple name and the qualified name are the same for a library.
1258 Symbol get qualifiedName => simpleName; 1256 Symbol get qualifiedName => simpleName;
1259 1257
1260 DeclarationMirror get owner => null; 1258 DeclarationMirror get owner => null;
1261 1259
1262 bool get isPrivate => false; 1260 bool get isPrivate => false;
1263 bool get isTopLevel => false; 1261 bool get isTopLevel => false;
1264 1262
1265 Type get _instantiator => null; 1263 Type get _instantiator => null;
1266 1264
1267 SourceLocation get location {
1268 throw new UnimplementedError('LibraryMirror.location is not implemented');
1269 }
1270
1271 Map<Symbol, DeclarationMirror> _declarations; 1265 Map<Symbol, DeclarationMirror> _declarations;
1272 Map<Symbol, DeclarationMirror> get declarations { 1266 Map<Symbol, DeclarationMirror> get declarations {
1273 if (_declarations != null) return _declarations; 1267 if (_declarations != null) return _declarations;
1274 return _declarations = 1268 return _declarations =
1275 new UnmodifiableMapView<Symbol, DeclarationMirror>(_members); 1269 new UnmodifiableMapView<Symbol, DeclarationMirror>(_members);
1276 } 1270 }
1277 1271
1278 Map<Symbol, Mirror> _cachedMembers; 1272 Map<Symbol, Mirror> _cachedMembers;
1279 Map<Symbol, Mirror> get _members { 1273 Map<Symbol, Mirror> get _members {
1280 if (_cachedMembers == null) { 1274 if (_cachedMembers == null) {
1281 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee)); 1275 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee));
1282 } 1276 }
1283 return _cachedMembers; 1277 return _cachedMembers;
1284 } 1278 }
1285 1279
1280 SourceLocation get location {
1281 return _location(_reflectee);
1282 }
1283
1286 List<InstanceMirror> get metadata { 1284 List<InstanceMirror> get metadata {
1287 // Get the metadata objects, convert them into InstanceMirrors using 1285 // Get the metadata objects, convert them into InstanceMirrors using
1288 // reflect() and then make them into a Dart list. 1286 // reflect() and then make them into a Dart list.
1289 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); 1287 return new UnmodifiableListView(_metadata(_reflectee).map(reflect));
1290 } 1288 }
1291 1289
1292 bool operator ==(other) { 1290 bool operator ==(other) {
1293 return this.runtimeType == other.runtimeType && 1291 return this.runtimeType == other.runtimeType &&
1294 this._reflectee == other._reflectee; 1292 this._reflectee == other._reflectee;
1295 } 1293 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 } 1391 }
1394 return _owner; 1392 return _owner;
1395 } 1393 }
1396 1394
1397 bool get isPrivate => _n(simpleName).startsWith('_') || 1395 bool get isPrivate => _n(simpleName).startsWith('_') ||
1398 _n(constructorName).startsWith('_'); 1396 _n(constructorName).startsWith('_');
1399 1397
1400 bool get isTopLevel => owner is LibraryMirror; 1398 bool get isTopLevel => owner is LibraryMirror;
1401 bool get isSynthetic => false; 1399 bool get isSynthetic => false;
1402 1400
1403 SourceLocation _location;
1404 SourceLocation get location {
1405 if (_location == null) {
1406 _location = _MethodMirror_location(_reflectee);
1407 }
1408 return _location;
1409 }
1410
1411 Type get _instantiator { 1401 Type get _instantiator {
1412 var o = owner; 1402 var o = owner;
1413 while (o is MethodMirror) o = o.owner; 1403 while (o is MethodMirror) o = o.owner;
1414 return o._instantiator; 1404 return o._instantiator;
1415 } 1405 }
1416 1406
1417 TypeMirror _returnType = null; 1407 TypeMirror _returnType = null;
1418 TypeMirror get returnType { 1408 TypeMirror get returnType {
1419 if (_returnType == null) { 1409 if (_returnType == null) {
1420 if (isConstructor) { 1410 if (isConstructor) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 native "MethodMirror_owner"; 1473 native "MethodMirror_owner";
1484 1474
1485 static dynamic _MethodMirror_return_type(reflectee, instantiator) 1475 static dynamic _MethodMirror_return_type(reflectee, instantiator)
1486 native "MethodMirror_return_type"; 1476 native "MethodMirror_return_type";
1487 1477
1488 List<ParameterMirror> _MethodMirror_parameters(reflectee) 1478 List<ParameterMirror> _MethodMirror_parameters(reflectee)
1489 native "MethodMirror_parameters"; 1479 native "MethodMirror_parameters";
1490 1480
1491 static String _MethodMirror_source(reflectee) 1481 static String _MethodMirror_source(reflectee)
1492 native "MethodMirror_source"; 1482 native "MethodMirror_source";
1493
1494 static SourceLocation _MethodMirror_location(reflectee)
1495 native "MethodMirror_location";
1496 } 1483 }
1497 1484
1498 class _LocalVariableMirror extends _LocalDeclarationMirror 1485 class _LocalVariableMirror extends _LocalDeclarationMirror
1499 implements VariableMirror { 1486 implements VariableMirror {
1500 final DeclarationMirror owner; 1487 final DeclarationMirror owner;
1501 final bool isStatic; 1488 final bool isStatic;
1502 final bool isFinal; 1489 final bool isFinal;
1503 final bool isConst; 1490 final bool isConst;
1504 1491
1505 _LocalVariableMirror(reflectee, 1492 _LocalVariableMirror(reflectee,
1506 String simpleName, 1493 String simpleName,
1507 this.owner, 1494 this.owner,
1508 this._type, 1495 this._type,
1509 this.isStatic, 1496 this.isStatic,
1510 this.isFinal, 1497 this.isFinal,
1511 this.isConst) 1498 this.isConst)
1512 : super(reflectee, _s(simpleName)); 1499 : super(reflectee, _s(simpleName));
1513 1500
1514 bool get isTopLevel => owner is LibraryMirror; 1501 bool get isTopLevel => owner is LibraryMirror;
1515 1502
1516 SourceLocation get location {
1517 throw new UnimplementedError('VariableMirror.location is not implemented');
1518 }
1519
1520 Type get _instantiator { 1503 Type get _instantiator {
1521 return owner._instantiator; 1504 return owner._instantiator;
1522 } 1505 }
1523 1506
1524 TypeMirror _type; 1507 TypeMirror _type;
1525 TypeMirror get type { 1508 TypeMirror get type {
1526 if (_type == null) { 1509 if (_type == null) {
1527 _type = reflectType(_VariableMirror_type(_reflectee, _instantiator)); 1510 _type = reflectType(_VariableMirror_type(_reflectee, _instantiator));
1528 } 1511 }
1529 return _type; 1512 return _type;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 return null; 1550 return null;
1568 } 1551 }
1569 if (_defaultValue == null) { 1552 if (_defaultValue == null) {
1570 _defaultValue = reflect(_defaultValueReflectee); 1553 _defaultValue = reflect(_defaultValueReflectee);
1571 } 1554 }
1572 return _defaultValue; 1555 return _defaultValue;
1573 } 1556 }
1574 1557
1575 bool get hasDefaultValue => _defaultValueReflectee != null; 1558 bool get hasDefaultValue => _defaultValueReflectee != null;
1576 1559
1560 SourceLocation get location {
1561 throw new UnsupportedError("ParameterMirror.location unimplemented");
1562 }
1563
1577 List<InstanceMirror> get metadata { 1564 List<InstanceMirror> get metadata {
1578 if (_unmirroredMetadata == null) return emptyList; 1565 if (_unmirroredMetadata == null) return emptyList;
1579 return new UnmodifiableListView(_unmirroredMetadata.map(reflect)); 1566 return new UnmodifiableListView(_unmirroredMetadata.map(reflect));
1580 } 1567 }
1581 1568
1582 Type get _instantiator { 1569 Type get _instantiator {
1583 var o = owner; 1570 var o = owner;
1584 while (o is MethodMirror) o = o.owner; 1571 while (o is MethodMirror) o = o.owner;
1585 return o._instantiator; 1572 return o._instantiator;
1586 } 1573 }
(...skipping 17 matching lines...) Expand all
1604 implements TypeMirror, DeclarationMirror { 1591 implements TypeMirror, DeclarationMirror {
1605 final Symbol simpleName; 1592 final Symbol simpleName;
1606 1593
1607 _SpecialTypeMirror(String name) : simpleName = _s(name); 1594 _SpecialTypeMirror(String name) : simpleName = _s(name);
1608 1595
1609 bool get isPrivate => false; 1596 bool get isPrivate => false;
1610 bool get isTopLevel => true; 1597 bool get isTopLevel => true;
1611 1598
1612 DeclarationMirror get owner => null; 1599 DeclarationMirror get owner => null;
1613 1600
1601 SourceLocation get location => null;
1614 List<InstanceMirror> get metadata => emptyList; 1602 List<InstanceMirror> get metadata => emptyList;
1615 1603
1616 bool get hasReflectedType => simpleName == #dynamic; 1604 bool get hasReflectedType => simpleName == #dynamic;
1617 Type get reflectedType { 1605 Type get reflectedType {
1618 if (simpleName == #dynamic) return dynamic; 1606 if (simpleName == #dynamic) return dynamic;
1619 throw new UnsupportedError("void has no reflected type"); 1607 throw new UnsupportedError("void has no reflected type");
1620 } 1608 }
1621 1609
1622 List<TypeVariableMirror> get typeVariables => emptyList; 1610 List<TypeVariableMirror> get typeVariables => emptyList;
1623 List<TypeMirror> get typeArguments => emptyList; 1611 List<TypeMirror> get typeArguments => emptyList;
1624 1612
1625 bool get isOriginalDeclaration => true; 1613 bool get isOriginalDeclaration => true;
1626 TypeMirror get originalDeclaration => this; 1614 TypeMirror get originalDeclaration => this;
1627 1615
1628 SourceLocation get location {
1629 throw new UnimplementedError('TypeMirror.location is not implemented');
1630 }
1631
1632 Symbol get qualifiedName => simpleName; 1616 Symbol get qualifiedName => simpleName;
1633 1617
1634 // TODO(11955): Remove once dynamicType and voidType are canonical objects in 1618 // TODO(11955): Remove once dynamicType and voidType are canonical objects in
1635 // the object store. 1619 // the object store.
1636 bool operator ==(other) { 1620 bool operator ==(other) {
1637 if (other is! _SpecialTypeMirror) { 1621 if (other is! _SpecialTypeMirror) {
1638 return false; 1622 return false;
1639 } 1623 }
1640 return this.simpleName == other.simpleName; 1624 return this.simpleName == other.simpleName;
1641 } 1625 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 if (typeMirror == null) { 1684 if (typeMirror == null) {
1701 typeMirror = makeLocalTypeMirror(key); 1685 typeMirror = makeLocalTypeMirror(key);
1702 _instanitationCache[key] = typeMirror; 1686 _instanitationCache[key] = typeMirror;
1703 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1687 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1704 _declarationCache[key] = typeMirror; 1688 _declarationCache[key] = typeMirror;
1705 } 1689 }
1706 } 1690 }
1707 return typeMirror; 1691 return typeMirror;
1708 } 1692 }
1709 } 1693 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698