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 class _InvocationMirror implements Invocation { | 5 class _InvocationMirror implements Invocation { |
6 // Constants describing the invocation type. | 6 // Constants describing the invocation type. |
7 // _FIELD cannot be generated by regular invocation mirrors. | 7 // _FIELD cannot be generated by regular invocation mirrors. |
8 static const int _METHOD = 0; | 8 static const int _METHOD = 0; |
9 static const int _GETTER = 1; | 9 static const int _GETTER = 1; |
10 static const int _SETTER = 2; | 10 static const int _SETTER = 2; |
11 static const int _FIELD = 3; | 11 static const int _FIELD = 3; |
12 static const int _TYPE_SHIFT = 0; | 12 static const int _TYPE_SHIFT = 0; |
13 static const int _TYPE_BITS = 2; | 13 static const int _TYPE_BITS = 2; |
14 static const int _TYPE_MASK = (1 << _TYPE_BITS) - 1; | 14 static const int _TYPE_MASK = (1 << _TYPE_BITS) - 1; |
15 | 15 |
16 // These values, except _DYNAMIC, are only used when throwing | 16 // These values, except _DYNAMIC and _SUPER, are only used when throwing |
17 // NoSuchMethodError for compile-time resolution failures. | 17 // NoSuchMethodError for compile-time resolution failures. |
18 static const int _DYNAMIC = 0; | 18 static const int _DYNAMIC = 0; |
19 static const int _STATIC = 1; | 19 static const int _SUPER = 1; |
20 static const int _CONSTRUCTOR = 2; | 20 static const int _STATIC = 2; |
21 static const int _TOP_LEVEL = 3; | 21 static const int _CONSTRUCTOR = 3; |
| 22 static const int _TOP_LEVEL = 4; |
22 static const int _CALL_SHIFT = _TYPE_BITS; | 23 static const int _CALL_SHIFT = _TYPE_BITS; |
23 static const int _CALL_BITS = 2; | 24 static const int _CALL_BITS = 3; |
24 static const int _CALL_MASK = (1 << _CALL_BITS) - 1; | 25 static const int _CALL_MASK = (1 << _CALL_BITS) - 1; |
25 | 26 |
26 // Internal representation of the invocation mirror. | 27 // Internal representation of the invocation mirror. |
27 final String _functionName; | 28 final String _functionName; |
28 final List _argumentsDescriptor; | 29 final List _argumentsDescriptor; |
29 final List _arguments; | 30 final List _arguments; |
| 31 final bool _isSuperInvocation; |
30 | 32 |
31 // External representation of the invocation mirror; populated on demand. | 33 // External representation of the invocation mirror; populated on demand. |
32 Symbol _memberName; | 34 Symbol _memberName; |
33 int _type; | 35 int _type; |
34 List _positionalArguments; | 36 List _positionalArguments; |
35 Map<Symbol, dynamic> _namedArguments; | 37 Map<Symbol, dynamic> _namedArguments; |
36 | 38 |
37 void _setMemberNameAndType() { | 39 void _setMemberNameAndType() { |
38 if (_functionName.startsWith("get:")) { | 40 if (_functionName.startsWith("get:")) { |
39 _type = _GETTER; | 41 _type = _GETTER; |
40 _memberName = | 42 _memberName = |
41 new _collection_dev.Symbol.unvalidated(_functionName.substring(4)); | 43 new _collection_dev.Symbol.unvalidated(_functionName.substring(4)); |
42 } else if (_functionName.startsWith("set:")) { | 44 } else if (_functionName.startsWith("set:")) { |
43 _type = _SETTER; | 45 _type = _SETTER; |
44 _memberName = | 46 _memberName = |
45 new _collection_dev.Symbol.unvalidated( | 47 new _collection_dev.Symbol.unvalidated( |
46 _functionName.substring(4) + "="); | 48 _functionName.substring(4) + "="); |
47 } else { | 49 } else { |
48 _type = _METHOD; | 50 _type = _isSuperInvocation ? (_SUPER << _CALL_SHIFT) | _METHOD : _METHOD; |
49 _memberName = new _collection_dev.Symbol.unvalidated(_functionName); | 51 _memberName = new _collection_dev.Symbol.unvalidated(_functionName); |
50 } | 52 } |
51 } | 53 } |
52 | 54 |
53 Symbol get memberName { | 55 Symbol get memberName { |
54 if (_memberName == null) { | 56 if (_memberName == null) { |
55 _setMemberNameAndType(); | 57 _setMemberNameAndType(); |
56 } | 58 } |
57 return _memberName; | 59 return _memberName; |
58 } | 60 } |
(...skipping 27 matching lines...) Expand all Loading... |
86 arg_value; | 88 arg_value; |
87 } | 89 } |
88 } | 90 } |
89 return _namedArguments; | 91 return _namedArguments; |
90 } | 92 } |
91 | 93 |
92 bool get isMethod { | 94 bool get isMethod { |
93 if (_type == null) { | 95 if (_type == null) { |
94 _setMemberNameAndType(); | 96 _setMemberNameAndType(); |
95 } | 97 } |
96 return _type == _METHOD; | 98 return (_type & _TYPE_MASK) == _METHOD; |
97 } | 99 } |
98 | 100 |
99 bool get isAccessor { | 101 bool get isAccessor { |
100 if (_type == null) { | 102 if (_type == null) { |
101 _setMemberNameAndType(); | 103 _setMemberNameAndType(); |
102 } | 104 } |
103 return _type != _METHOD; | 105 return (_type & _TYPE_MASK) != _METHOD; |
104 } | 106 } |
105 | 107 |
106 bool get isGetter { | 108 bool get isGetter { |
107 if (_type == null) { | 109 if (_type == null) { |
108 _setMemberNameAndType(); | 110 _setMemberNameAndType(); |
109 } | 111 } |
110 return _type == _GETTER; | 112 return (_type & _TYPE_MASK) == _GETTER; |
111 } | 113 } |
112 | 114 |
113 bool get isSetter { | 115 bool get isSetter { |
114 if (_type == null) { | 116 if (_type == null) { |
115 _setMemberNameAndType(); | 117 _setMemberNameAndType(); |
116 } | 118 } |
117 return _type == _SETTER; | 119 return (_type & _TYPE_MASK) == _SETTER; |
118 } | 120 } |
119 | 121 |
120 _InvocationMirror(this._functionName, | 122 _InvocationMirror(this._functionName, |
121 this._argumentsDescriptor, | 123 this._argumentsDescriptor, |
122 this._arguments); | 124 this._arguments, |
| 125 this._isSuperInvocation); |
123 | 126 |
124 static _allocateInvocationMirror(String functionName, | 127 static _allocateInvocationMirror(String functionName, |
125 List argumentsDescriptor, | 128 List argumentsDescriptor, |
126 List arguments) { | 129 List arguments, |
127 return new _InvocationMirror(functionName, argumentsDescriptor, arguments); | 130 bool isSuperInvocation) { |
| 131 return new _InvocationMirror(functionName, |
| 132 argumentsDescriptor, |
| 133 arguments, |
| 134 isSuperInvocation); |
128 } | 135 } |
129 | 136 |
130 static _invoke(Object receiver, | 137 static _invoke(Object receiver, |
131 String functionName, | 138 String functionName, |
132 List argumentsDescriptor, | 139 List argumentsDescriptor, |
133 List arguments) | 140 List arguments) |
134 native "InvocationMirror_invoke"; | 141 native "InvocationMirror_invoke"; |
135 | 142 |
136 _invokeOn(Object receiver) { | 143 _invokeOn(Object receiver) { |
137 return _invoke(receiver, _functionName, _argumentsDescriptor, _arguments); | 144 return _invoke(receiver, _functionName, _argumentsDescriptor, _arguments); |
138 } | 145 } |
139 | 146 |
140 // TODO(ahe): This is a hack. See _LocalInstanceMirrorImpl.delegate | 147 // TODO(ahe): This is a hack. See _LocalInstanceMirrorImpl.delegate |
141 // in mirrors_impl.dart | 148 // in mirrors_impl.dart |
142 static final _invokeOnClosure = (x, y) => y._invokeOn(x); | 149 static final _invokeOnClosure = (x, y) => y._invokeOn(x); |
143 } | 150 } |
OLD | NEW |