| 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 _LOCAL_VAR = 4; | 12 static const int _LOCAL_VAR = 4; |
| 13 static const int _TYPE_SHIFT = 0; | 13 static const int _TYPE_SHIFT = 0; |
| 14 static const int _TYPE_BITS = 3; | 14 static const int _TYPE_BITS = 3; |
| 15 static const int _TYPE_MASK = (1 << _TYPE_BITS) - 1; | 15 static const int _TYPE_MASK = (1 << _TYPE_BITS) - 1; |
| 16 | 16 |
| 17 // These values, except _DYNAMIC and _SUPER, are only used when throwing | 17 // These values, except _DYNAMIC and _SUPER, are only used when throwing |
| 18 // NoSuchMethodError for compile-time resolution failures. | 18 // NoSuchMethodError for compile-time resolution failures. |
| 19 static const int _DYNAMIC = 0; | 19 static const int _DYNAMIC = 0; |
| 20 static const int _SUPER = 1; | 20 static const int _SUPER = 1; |
| 21 static const int _STATIC = 2; | 21 static const int _STATIC = 2; |
| 22 static const int _CONSTRUCTOR = 3; | 22 static const int _CONSTRUCTOR = 3; |
| 23 static const int _TOP_LEVEL = 4; | 23 static const int _TOP_LEVEL = 4; |
| 24 static const int _CALL_SHIFT = _TYPE_BITS; | 24 static const int _CALL_SHIFT = _TYPE_BITS; |
| 25 static const int _CALL_BITS = 3; | 25 static const int _CALL_BITS = 3; |
| 26 static const int _CALL_MASK = (1 << _CALL_BITS) - 1; | 26 static const int _CALL_MASK = (1 << _CALL_BITS) - 1; |
| 27 | 27 |
| 28 // ArgumentsDescriptor layout. Keep in sync with enum in dart_entry.h. |
| 29 static const int _TYPE_ARGS_LEN = 0; |
| 30 static const int _COUNT = 1; |
| 31 static const int _POSITIONAL_COUNT = 2; |
| 32 static const int _FIRST_NAMED_ENTRY = 3; |
| 33 |
| 28 // Internal representation of the invocation mirror. | 34 // Internal representation of the invocation mirror. |
| 29 final String _functionName; | 35 final String _functionName; |
| 30 final List _argumentsDescriptor; | 36 final List _argumentsDescriptor; |
| 31 final List _arguments; | 37 final List _arguments; |
| 32 final bool _isSuperInvocation; | 38 final bool _isSuperInvocation; |
| 33 | 39 |
| 34 // External representation of the invocation mirror; populated on demand. | 40 // External representation of the invocation mirror; populated on demand. |
| 35 Symbol _memberName; | 41 Symbol _memberName; |
| 36 int _type; | 42 int _type; |
| 37 List _positionalArguments; | 43 List _positionalArguments; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 53 | 59 |
| 54 Symbol get memberName { | 60 Symbol get memberName { |
| 55 if (_memberName == null) { | 61 if (_memberName == null) { |
| 56 _setMemberNameAndType(); | 62 _setMemberNameAndType(); |
| 57 } | 63 } |
| 58 return _memberName; | 64 return _memberName; |
| 59 } | 65 } |
| 60 | 66 |
| 61 List get positionalArguments { | 67 List get positionalArguments { |
| 62 if (_positionalArguments == null) { | 68 if (_positionalArguments == null) { |
| 63 int numPositionalArguments = _argumentsDescriptor[1]; | 69 int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT]; |
| 64 // Don't count receiver. | 70 // Don't count receiver. |
| 65 if (numPositionalArguments == 1) { | 71 if (numPositionalArguments == 1) { |
| 66 return _positionalArguments = const []; | 72 return _positionalArguments = const []; |
| 67 } | 73 } |
| 68 // Exclude receiver. | 74 // Exclude receiver. |
| 69 _positionalArguments = | 75 _positionalArguments = |
| 70 new _ImmutableList._from(_arguments, 1, numPositionalArguments - 1); | 76 new _ImmutableList._from(_arguments, 1, numPositionalArguments - 1); |
| 71 } | 77 } |
| 72 return _positionalArguments; | 78 return _positionalArguments; |
| 73 } | 79 } |
| 74 | 80 |
| 75 Map<Symbol, dynamic> get namedArguments { | 81 Map<Symbol, dynamic> get namedArguments { |
| 76 if (_namedArguments == null) { | 82 if (_namedArguments == null) { |
| 77 int numArguments = _argumentsDescriptor[0] - 1; // Exclude receiver. | 83 int numArguments = _argumentsDescriptor[_COUNT] - 1; // Exclude receiver. |
| 78 int numPositionalArguments = _argumentsDescriptor[1] - 1; | 84 int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT] - 1; |
| 79 int numNamedArguments = numArguments - numPositionalArguments; | 85 int numNamedArguments = numArguments - numPositionalArguments; |
| 80 if (numNamedArguments == 0) { | 86 if (numNamedArguments == 0) { |
| 81 return _namedArguments = const {}; | 87 return _namedArguments = const {}; |
| 82 } | 88 } |
| 83 _namedArguments = new Map<Symbol, dynamic>(); | 89 _namedArguments = new Map<Symbol, dynamic>(); |
| 84 for (int i = 0; i < numNamedArguments; i++) { | 90 for (int i = 0; i < numNamedArguments; i++) { |
| 85 String arg_name = _argumentsDescriptor[2 + 2 * i]; | 91 int namedEntryIndex = _FIRST_NAMED_ENTRY + 2 * i; |
| 86 var arg_value = _arguments[_argumentsDescriptor[3 + 2 * i]]; | 92 String arg_name = _argumentsDescriptor[namedEntryIndex]; |
| 93 var arg_value = _arguments[_argumentsDescriptor[namedEntryIndex + 1]]; |
| 87 _namedArguments[new internal.Symbol.unvalidated(arg_name)] = arg_value; | 94 _namedArguments[new internal.Symbol.unvalidated(arg_name)] = arg_value; |
| 88 } | 95 } |
| 89 _namedArguments = new Map.unmodifiable(_namedArguments); | 96 _namedArguments = new Map.unmodifiable(_namedArguments); |
| 90 } | 97 } |
| 91 return _namedArguments; | 98 return _namedArguments; |
| 92 } | 99 } |
| 93 | 100 |
| 94 bool get isMethod { | 101 bool get isMethod { |
| 95 if (_type == null) { | 102 if (_type == null) { |
| 96 _setMemberNameAndType(); | 103 _setMemberNameAndType(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 121 | 128 |
| 122 _InvocationMirror(this._functionName, this._argumentsDescriptor, | 129 _InvocationMirror(this._functionName, this._argumentsDescriptor, |
| 123 this._arguments, this._isSuperInvocation); | 130 this._arguments, this._isSuperInvocation); |
| 124 | 131 |
| 125 static _allocateInvocationMirror(String functionName, | 132 static _allocateInvocationMirror(String functionName, |
| 126 List argumentsDescriptor, List arguments, bool isSuperInvocation) { | 133 List argumentsDescriptor, List arguments, bool isSuperInvocation) { |
| 127 return new _InvocationMirror( | 134 return new _InvocationMirror( |
| 128 functionName, argumentsDescriptor, arguments, isSuperInvocation); | 135 functionName, argumentsDescriptor, arguments, isSuperInvocation); |
| 129 } | 136 } |
| 130 } | 137 } |
| OLD | NEW |