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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/invocation_mirror_patch.dart
diff --git a/runtime/lib/invocation_mirror_patch.dart b/runtime/lib/invocation_mirror_patch.dart
index ef325e35b8e917467629d3da7d4560e3f58b3be1..7fd57bde529c57f6df11ac2c32b68292ca0283de 100644
--- a/runtime/lib/invocation_mirror_patch.dart
+++ b/runtime/lib/invocation_mirror_patch.dart
@@ -5,6 +5,7 @@
// NOTE: When making changes to this class, please also update
// `VmTarget.instantiateInvocation` and `VmTarget._invocationType` in
// `pkg/kernel/lib/target/vm.dart`.
+// TODO(regis): See above NOTE.
class _InvocationMirror implements Invocation {
// Constants describing the invocation type.
// _FIELD cannot be generated by regular invocation mirrors.
@@ -43,6 +44,7 @@ class _InvocationMirror implements Invocation {
// External representation of the invocation mirror; populated on demand.
Symbol _memberName;
int _type;
+ List _typeArguments;
List _positionalArguments;
Map<Symbol, dynamic> _namedArguments;
@@ -67,16 +69,36 @@ class _InvocationMirror implements Invocation {
return _memberName;
}
+ List get typeArguments {
+ if (_typeArguments == null) {
+ int typeArgsLen = _argumentsDescriptor[_TYPE_ARGS_LEN];
+ if (typeArgsLen == 0) {
+ return _typeArguments = const [];
+ }
+ // A TypeArguments object does not have a corresponding Dart class and
+ // cannot be accessed as an array in Dart. Therefore, we need a native
+ // call to unpack the individual types into a list.
+ _typeArguments = _unpackTypeArguments(_arguments[0]);
+ }
+ return _typeArguments;
+ }
+
+ // Unpack the given TypeArguments object into a new list of individual types.
+ static List _unpackTypeArguments(typeArguments)
+ native "InvocationMirror_unpackTypeArguments";
+
List get positionalArguments {
if (_positionalArguments == null) {
- int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT];
- // Don't count receiver.
- if (numPositionalArguments == 1) {
+ // The argument descriptor counts the receiver, but not the type arguments
+ // as positional arguments.
+ int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT] - 1;
+ if (numPositionalArguments == 0) {
return _positionalArguments = const [];
}
- // Exclude receiver.
- _positionalArguments =
- new _ImmutableList._from(_arguments, 1, numPositionalArguments - 1);
+ // Exclude receiver and type args in the returned list.
+ int receiverIndex = _argumentsDescriptor[_TYPE_ARGS_LEN] > 0 ? 1 : 0;
+ _positionalArguments = new _ImmutableList._from(
+ _arguments, receiverIndex + 1, numPositionalArguments);
}
return _positionalArguments;
}
@@ -89,11 +111,13 @@ class _InvocationMirror implements Invocation {
if (numNamedArguments == 0) {
return _namedArguments = const {};
}
+ int receiverIndex = _argumentsDescriptor[_TYPE_ARGS_LEN] > 0 ? 1 : 0;
_namedArguments = new Map<Symbol, dynamic>();
for (int i = 0; i < numNamedArguments; i++) {
int namedEntryIndex = _FIRST_NAMED_ENTRY + 2 * i;
String arg_name = _argumentsDescriptor[namedEntryIndex];
- var arg_value = _arguments[_argumentsDescriptor[namedEntryIndex + 1]];
+ var arg_value = _arguments[
+ receiverIndex + _argumentsDescriptor[namedEntryIndex + 1]];
_namedArguments[new internal.Symbol.unvalidated(arg_name)] = arg_value;
}
_namedArguments = new Map.unmodifiable(_namedArguments);
« 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