Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // These values are allowed to be passed directly over the wire. | 7 // These values are allowed to be passed directly over the wire. |
| 8 bool _isSimpleValue(var value) { | 8 bool _isSimpleValue(var value) { |
| 9 return (value == null || value is num || value is String || value is bool); | 9 return (value == null || value is num || value is String || value is bool); |
| 10 } | 10 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 : this.libraries = _createLibrariesMap(libraries), | 96 : this.libraries = _createLibrariesMap(libraries), |
| 97 _functionTypes = new Map<String, FunctionTypeMirror>(); | 97 _functionTypes = new Map<String, FunctionTypeMirror>(); |
| 98 | 98 |
| 99 final Map<Uri, LibraryMirror> libraries; | 99 final Map<Uri, LibraryMirror> libraries; |
| 100 final IsolateMirror isolate; | 100 final IsolateMirror isolate; |
| 101 | 101 |
| 102 TypeMirror _dynamicType = null; | 102 TypeMirror _dynamicType = null; |
| 103 | 103 |
| 104 TypeMirror get dynamicType { | 104 TypeMirror get dynamicType { |
| 105 if (_dynamicType == null) { | 105 if (_dynamicType == null) { |
| 106 _dynamicType = new _SpecialTypeMirrorImpl(_s('dynamic')); | 106 _dynamicType = new _SpecialTypeMirrorImpl('dynamic'); |
| 107 } | 107 } |
| 108 return _dynamicType; | 108 return _dynamicType; |
| 109 } | 109 } |
| 110 | 110 |
| 111 TypeMirror _voidType = null; | 111 TypeMirror _voidType = null; |
| 112 | 112 |
| 113 TypeMirror get voidType { | 113 TypeMirror get voidType { |
| 114 if (_voidType == null) { | 114 if (_voidType == null) { |
| 115 _voidType = new _SpecialTypeMirrorImpl(_s('void')); | 115 _voidType = new _SpecialTypeMirrorImpl('void'); |
| 116 } | 116 } |
| 117 return _voidType; | 117 return _voidType; |
| 118 } | 118 } |
| 119 | 119 |
| 120 final Map<String, FunctionTypeMirror> _functionTypes; | 120 final Map<String, FunctionTypeMirror> _functionTypes; |
| 121 FunctionTypeMirror _lookupFunctionTypeMirror( | 121 FunctionTypeMirror _lookupFunctionTypeMirror( |
| 122 TypeMirror returnType, | 122 TypeMirror returnType, |
| 123 List<ParameterMirror> parameters) { | 123 List<ParameterMirror> parameters) { |
| 124 var sigString = _makeSignatureString(returnType, parameters); | 124 var sigString = _makeSignatureString(returnType, parameters); |
| 125 var mirror = _functionTypes[sigString]; | 125 var mirror = _functionTypes[sigString]; |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 | 865 |
| 866 _invokeSetter(reflectee, setterName, value) | 866 _invokeSetter(reflectee, setterName, value) |
| 867 native 'LibraryMirror_invokeSetter'; | 867 native 'LibraryMirror_invokeSetter'; |
| 868 } | 868 } |
| 869 | 869 |
| 870 class _LocalMethodMirrorImpl extends _LocalDeclarationMirrorImpl | 870 class _LocalMethodMirrorImpl extends _LocalDeclarationMirrorImpl |
| 871 implements MethodMirror { | 871 implements MethodMirror { |
| 872 _LocalMethodMirrorImpl(reflectee, | 872 _LocalMethodMirrorImpl(reflectee, |
| 873 this._owner, | 873 this._owner, |
| 874 this.parameters, | 874 this.parameters, |
| 875 this._returnType, | |
| 876 this.isStatic, | 875 this.isStatic, |
| 877 this.isAbstract, | 876 this.isAbstract, |
| 878 this.isGetter, | 877 this.isGetter, |
| 879 this.isSetter, | 878 this.isSetter, |
| 880 this.isConstructor, | 879 this.isConstructor, |
| 881 this.isConstConstructor, | 880 this.isConstConstructor, |
| 882 this.isGenerativeConstructor, | 881 this.isGenerativeConstructor, |
| 883 this.isRedirectingConstructor, | 882 this.isRedirectingConstructor, |
| 884 this.isFactoryConstructor) : super(reflectee); | 883 this.isFactoryConstructor) : super(reflectee); |
| 885 | 884 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 918 _n(constructorName).startsWith('_'); | 917 _n(constructorName).startsWith('_'); |
| 919 } | 918 } |
| 920 | 919 |
| 921 bool get isTopLevel => owner is LibraryMirror; | 920 bool get isTopLevel => owner is LibraryMirror; |
| 922 | 921 |
| 923 SourceLocation get location { | 922 SourceLocation get location { |
| 924 throw new UnimplementedError( | 923 throw new UnimplementedError( |
| 925 'MethodMirror.location is not implemented'); | 924 'MethodMirror.location is not implemented'); |
| 926 } | 925 } |
| 927 | 926 |
| 928 var _returnType; | 927 TypeMirror _returnType = null; |
| 929 TypeMirror get returnType { | 928 TypeMirror get returnType { |
| 930 if (_returnType is! Mirror) { | 929 if (isConstructor) { |
|
rmacnak
2013/07/19 20:37:22
What if _returnType isn't null? This will fetch it
Michael Lippautz (Google)
2013/07/19 20:53:01
Fixed.
| |
| 931 _returnType = _returnType.resolve(mirrors); | 930 _returnType = _owner; |
| 931 } else { | |
| 932 _returnType = _MethodMirror_return_type(_reflectee); | |
| 932 } | 933 } |
| 933 return _returnType; | 934 return _returnType; |
| 934 } | 935 } |
| 935 | 936 |
| 936 final List<ParameterMirror> parameters; | 937 final List<ParameterMirror> parameters; |
| 937 | 938 |
| 938 final bool isStatic; | 939 final bool isStatic; |
| 939 final bool isAbstract; | 940 final bool isAbstract; |
| 940 | 941 |
| 941 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor; | 942 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 975 final bool isRedirectingConstructor; | 976 final bool isRedirectingConstructor; |
| 976 final bool isFactoryConstructor; | 977 final bool isFactoryConstructor; |
| 977 | 978 |
| 978 String toString() => "MethodMirror on '${_n(simpleName)}'"; | 979 String toString() => "MethodMirror on '${_n(simpleName)}'"; |
| 979 | 980 |
| 980 static String _MethodMirror_name(reflectee) | 981 static String _MethodMirror_name(reflectee) |
| 981 native "MethodMirror_name"; | 982 native "MethodMirror_name"; |
| 982 | 983 |
| 983 static dynamic _MethodMirror_owner(reflectee) | 984 static dynamic _MethodMirror_owner(reflectee) |
| 984 native "MethodMirror_owner"; | 985 native "MethodMirror_owner"; |
| 986 | |
| 987 static dynamic _MethodMirror_return_type(reflectee) | |
| 988 native "MethodMirror_return_type"; | |
| 985 } | 989 } |
| 986 | 990 |
| 987 class _LocalVariableMirrorImpl extends _LocalDeclarationMirrorImpl | 991 class _LocalVariableMirrorImpl extends _LocalDeclarationMirrorImpl |
| 988 implements VariableMirror { | 992 implements VariableMirror { |
| 989 _LocalVariableMirrorImpl(reflectee, | 993 _LocalVariableMirrorImpl(reflectee, |
| 990 String simpleName, | 994 String simpleName, |
| 991 this._owner, | 995 this._owner, |
| 992 this._type, | 996 this._type, |
| 993 this.isStatic, | 997 this.isStatic, |
| 994 this.isFinal) | 998 this.isFinal) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 | 1063 |
| 1060 // TODO(11418): Implement. | 1064 // TODO(11418): Implement. |
| 1061 List<InstanceMirror> get metadata { | 1065 List<InstanceMirror> get metadata { |
| 1062 throw new UnimplementedError( | 1066 throw new UnimplementedError( |
| 1063 'ParameterMirror.metadata is not implemented'); | 1067 'ParameterMirror.metadata is not implemented'); |
| 1064 } | 1068 } |
| 1065 } | 1069 } |
| 1066 | 1070 |
| 1067 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl | 1071 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl |
| 1068 implements TypeMirror, DeclarationMirror { | 1072 implements TypeMirror, DeclarationMirror { |
| 1069 _SpecialTypeMirrorImpl(this.simpleName); | 1073 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); |
| 1070 | 1074 |
| 1071 final bool isPrivate = false; | 1075 final bool isPrivate = false; |
| 1072 final bool isTopLevel = true; | 1076 final bool isTopLevel = true; |
| 1073 | 1077 |
| 1074 // Fixed length 0, therefore immutable. | 1078 // Fixed length 0, therefore immutable. |
| 1075 final List<InstanceMirror> metadata = new List(0); | 1079 final List<InstanceMirror> metadata = new List(0); |
| 1076 | 1080 |
| 1077 final DeclarationMirror owner = null; | 1081 final DeclarationMirror owner = null; |
| 1078 final Symbol simpleName; | 1082 final Symbol simpleName; |
| 1079 | 1083 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); | 1142 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); |
| 1139 static ClassMirror reflectClass(Type key) { | 1143 static ClassMirror reflectClass(Type key) { |
| 1140 var classMirror = _classMirrorCache[key]; | 1144 var classMirror = _classMirrorCache[key]; |
| 1141 if (classMirror == null) { | 1145 if (classMirror == null) { |
| 1142 classMirror = makeLocalClassMirror(key); | 1146 classMirror = makeLocalClassMirror(key); |
| 1143 _classMirrorCache[key] = classMirror; | 1147 _classMirrorCache[key] = classMirror; |
| 1144 } | 1148 } |
| 1145 return classMirror; | 1149 return classMirror; |
| 1146 } | 1150 } |
| 1147 } | 1151 } |
| OLD | NEW |