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

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

Issue 3007603002: [VM generic function reification] Support generic functions in Invocation class. (Closed)
Patch Set: address review comment Created 3 years, 3 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
« no previous file with comments | « no previous file | runtime/lib/object.cc » ('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 // NOTE: When making changes to this class, please also update 5 // NOTE: When making changes to this class, please also update
6 // `VmTarget.instantiateInvocation` and `VmTarget._invocationType` in 6 // `VmTarget.instantiateInvocation` and `VmTarget._invocationType` in
7 // `pkg/kernel/lib/target/vm.dart`. 7 // `pkg/kernel/lib/target/vm.dart`.
8 // TODO(regis): See above NOTE.
8 class _InvocationMirror implements Invocation { 9 class _InvocationMirror implements Invocation {
9 // Constants describing the invocation type. 10 // Constants describing the invocation type.
10 // _FIELD cannot be generated by regular invocation mirrors. 11 // _FIELD cannot be generated by regular invocation mirrors.
11 static const int _METHOD = 0; 12 static const int _METHOD = 0;
12 static const int _GETTER = 1; 13 static const int _GETTER = 1;
13 static const int _SETTER = 2; 14 static const int _SETTER = 2;
14 static const int _FIELD = 3; 15 static const int _FIELD = 3;
15 static const int _LOCAL_VAR = 4; 16 static const int _LOCAL_VAR = 4;
16 static const int _TYPE_SHIFT = 0; 17 static const int _TYPE_SHIFT = 0;
17 static const int _TYPE_BITS = 3; 18 static const int _TYPE_BITS = 3;
(...skipping 18 matching lines...) Expand all
36 37
37 // Internal representation of the invocation mirror. 38 // Internal representation of the invocation mirror.
38 final String _functionName; 39 final String _functionName;
39 final List _argumentsDescriptor; 40 final List _argumentsDescriptor;
40 final List _arguments; 41 final List _arguments;
41 final bool _isSuperInvocation; 42 final bool _isSuperInvocation;
42 43
43 // External representation of the invocation mirror; populated on demand. 44 // External representation of the invocation mirror; populated on demand.
44 Symbol _memberName; 45 Symbol _memberName;
45 int _type; 46 int _type;
47 List _typeArguments;
46 List _positionalArguments; 48 List _positionalArguments;
47 Map<Symbol, dynamic> _namedArguments; 49 Map<Symbol, dynamic> _namedArguments;
48 50
49 void _setMemberNameAndType() { 51 void _setMemberNameAndType() {
50 if (_functionName.startsWith("get:")) { 52 if (_functionName.startsWith("get:")) {
51 _type = _GETTER; 53 _type = _GETTER;
52 _memberName = new internal.Symbol.unvalidated(_functionName.substring(4)); 54 _memberName = new internal.Symbol.unvalidated(_functionName.substring(4));
53 } else if (_functionName.startsWith("set:")) { 55 } else if (_functionName.startsWith("set:")) {
54 _type = _SETTER; 56 _type = _SETTER;
55 _memberName = 57 _memberName =
56 new internal.Symbol.unvalidated(_functionName.substring(4) + "="); 58 new internal.Symbol.unvalidated(_functionName.substring(4) + "=");
57 } else { 59 } else {
58 _type = _isSuperInvocation ? (_SUPER << _CALL_SHIFT) | _METHOD : _METHOD; 60 _type = _isSuperInvocation ? (_SUPER << _CALL_SHIFT) | _METHOD : _METHOD;
59 _memberName = new internal.Symbol.unvalidated(_functionName); 61 _memberName = new internal.Symbol.unvalidated(_functionName);
60 } 62 }
61 } 63 }
62 64
63 Symbol get memberName { 65 Symbol get memberName {
64 if (_memberName == null) { 66 if (_memberName == null) {
65 _setMemberNameAndType(); 67 _setMemberNameAndType();
66 } 68 }
67 return _memberName; 69 return _memberName;
68 } 70 }
69 71
72 List get typeArguments {
73 if (_typeArguments == null) {
74 int typeArgsLen = _argumentsDescriptor[_TYPE_ARGS_LEN];
75 if (typeArgsLen == 0) {
76 return _typeArguments = const [];
77 }
78 // A TypeArguments object does not have a corresponding Dart class and
79 // cannot be accessed as an array in Dart. Therefore, we need a native
80 // call to unpack the individual types into a list.
81 _typeArguments = _unpackTypeArguments(_arguments[0]);
82 }
83 return _typeArguments;
84 }
85
86 // Unpack the given TypeArguments object into a new list of individual types.
87 static List _unpackTypeArguments(typeArguments)
88 native "InvocationMirror_unpackTypeArguments";
89
70 List get positionalArguments { 90 List get positionalArguments {
71 if (_positionalArguments == null) { 91 if (_positionalArguments == null) {
72 int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT]; 92 // The argument descriptor counts the receiver, but not the type arguments
73 // Don't count receiver. 93 // as positional arguments.
74 if (numPositionalArguments == 1) { 94 int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT] - 1;
95 if (numPositionalArguments == 0) {
75 return _positionalArguments = const []; 96 return _positionalArguments = const [];
76 } 97 }
77 // Exclude receiver. 98 // Exclude receiver and type args in the returned list.
78 _positionalArguments = 99 int receiverIndex = _argumentsDescriptor[_TYPE_ARGS_LEN] > 0 ? 1 : 0;
79 new _ImmutableList._from(_arguments, 1, numPositionalArguments - 1); 100 _positionalArguments = new _ImmutableList._from(
101 _arguments, receiverIndex + 1, numPositionalArguments);
80 } 102 }
81 return _positionalArguments; 103 return _positionalArguments;
82 } 104 }
83 105
84 Map<Symbol, dynamic> get namedArguments { 106 Map<Symbol, dynamic> get namedArguments {
85 if (_namedArguments == null) { 107 if (_namedArguments == null) {
86 int numArguments = _argumentsDescriptor[_COUNT] - 1; // Exclude receiver. 108 int numArguments = _argumentsDescriptor[_COUNT] - 1; // Exclude receiver.
87 int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT] - 1; 109 int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT] - 1;
88 int numNamedArguments = numArguments - numPositionalArguments; 110 int numNamedArguments = numArguments - numPositionalArguments;
89 if (numNamedArguments == 0) { 111 if (numNamedArguments == 0) {
90 return _namedArguments = const {}; 112 return _namedArguments = const {};
91 } 113 }
114 int receiverIndex = _argumentsDescriptor[_TYPE_ARGS_LEN] > 0 ? 1 : 0;
92 _namedArguments = new Map<Symbol, dynamic>(); 115 _namedArguments = new Map<Symbol, dynamic>();
93 for (int i = 0; i < numNamedArguments; i++) { 116 for (int i = 0; i < numNamedArguments; i++) {
94 int namedEntryIndex = _FIRST_NAMED_ENTRY + 2 * i; 117 int namedEntryIndex = _FIRST_NAMED_ENTRY + 2 * i;
95 String arg_name = _argumentsDescriptor[namedEntryIndex]; 118 String arg_name = _argumentsDescriptor[namedEntryIndex];
96 var arg_value = _arguments[_argumentsDescriptor[namedEntryIndex + 1]]; 119 var arg_value = _arguments[
120 receiverIndex + _argumentsDescriptor[namedEntryIndex + 1]];
97 _namedArguments[new internal.Symbol.unvalidated(arg_name)] = arg_value; 121 _namedArguments[new internal.Symbol.unvalidated(arg_name)] = arg_value;
98 } 122 }
99 _namedArguments = new Map.unmodifiable(_namedArguments); 123 _namedArguments = new Map.unmodifiable(_namedArguments);
100 } 124 }
101 return _namedArguments; 125 return _namedArguments;
102 } 126 }
103 127
104 bool get isMethod { 128 bool get isMethod {
105 if (_type == null) { 129 if (_type == null) {
106 _setMemberNameAndType(); 130 _setMemberNameAndType();
(...skipping 24 matching lines...) Expand all
131 155
132 _InvocationMirror(this._functionName, this._argumentsDescriptor, 156 _InvocationMirror(this._functionName, this._argumentsDescriptor,
133 this._arguments, this._isSuperInvocation); 157 this._arguments, this._isSuperInvocation);
134 158
135 static _allocateInvocationMirror(String functionName, 159 static _allocateInvocationMirror(String functionName,
136 List argumentsDescriptor, List arguments, bool isSuperInvocation) { 160 List argumentsDescriptor, List arguments, bool isSuperInvocation) {
137 return new _InvocationMirror( 161 return new _InvocationMirror(
138 functionName, argumentsDescriptor, arguments, isSuperInvocation); 162 functionName, argumentsDescriptor, arguments, isSuperInvocation);
139 } 163 }
140 } 164 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698