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

Unified Diff: pkg/kernel/lib/target/vm.dart

Issue 2897683002: Move code for instantiating Invocation to Target. (Closed)
Patch Set: Rename vmTarget to targetInfo. Created 3 years, 7 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 | « pkg/kernel/lib/target/targets.dart ('k') | pkg/kernel/lib/transformations/mixin_full_resolution.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/target/vm.dart
diff --git a/pkg/kernel/lib/target/vm.dart b/pkg/kernel/lib/target/vm.dart
index 003a21125e0aa5351b3fe3939f6440e2b165cdf2..7959de5ccc933397e8dd79c2e5b5f123d44efc41 100644
--- a/pkg/kernel/lib/target/vm.dart
+++ b/pkg/kernel/lib/target/vm.dart
@@ -57,7 +57,7 @@ class VmTarget extends Target {
ClassHierarchy _hierarchy;
void performModularTransformations(Program program) {
- var mixins = new mix.MixinFullResolution()..transform(program);
+ var mixins = new mix.MixinFullResolution(this)..transform(program);
_hierarchy = mixins.hierarchy;
}
@@ -99,4 +99,68 @@ class VmTarget extends Target {
void performErasure(Program program) {
new Erasure().transform(program);
}
+
+ @override
+ Expression instantiateInvocation(Member target, Expression receiver,
+ String name, Arguments arguments, int offset, bool isSuper) {
+ // See [_InvocationMirror]
+ // (../../../../runtime/lib/invocation_mirror_patch.dart).
+ // The _InvocationMirror constructor takes the following arguments:
+ // * Method name (a string).
+ // * An arguments descriptor - a list consisting of:
+ // - length of passed type argument vector, 0 if none passed.
+ // - number of arguments (including receiver).
+ // - number of positional arguments (including receiver).
+ // - pairs (2 entries in the list) of
+ // * named arguments name.
+ // * index of named argument in arguments list.
+ // * A list of arguments, where the first ones are the positional arguments.
+ // * Whether it's a super invocation or not.
+
+ int typeArgsLen = 0; // TODO(regis): Type arguments of generic function.
+ int numPositionalArguments = arguments.positional.length;
+ numPositionalArguments++; // Include the receiver.
+ int numArguments = numPositionalArguments + arguments.named.length;
+ List<Expression> argumentsDescriptor = [
+ new IntLiteral(typeArgsLen)..fileOffset = offset,
+ new IntLiteral(numArguments)..fileOffset = offset,
+ new IntLiteral(numPositionalArguments)..fileOffset = offset,
+ ];
+
+ List<Expression> argumentsList = <Expression>[receiver];
+ argumentsList.addAll(arguments.positional);
+
+ for (NamedExpression argument in arguments.named) {
+ argumentsDescriptor.add(
+ new StringLiteral(argument.name)..fileOffset = argument.fileOffset);
+ argumentsDescriptor.add(new IntLiteral(argumentsList.length)
+ ..fileOffset = argument.fileOffset);
+ argumentsList.add(argument.value);
+ }
+
+ Arguments constructorArguments = new Arguments([
+ new StringLiteral(name)..fileOffset = offset,
+ _fixedLengthList(argumentsDescriptor, arguments.fileOffset),
+ _fixedLengthList(argumentsList, arguments.fileOffset),
+ new BoolLiteral(isSuper)..fileOffset = arguments.fileOffset,
+ ]);
+
+ return (target is Constructor
+ ? new ConstructorInvocation(target, constructorArguments)
+ : new StaticInvocation(target, constructorArguments))
+ ..fileOffset = offset;
+ }
+
+ Expression _fixedLengthList(List<Expression> elements, int charOffset) {
+ // TODO(ahe): It's possible that it would be better to create a fixed-length
+ // list first, and then populate it. That would create fewer objects. But as
+ // this is currently only used in (statically resolved) no-such-method
+ // handling, the current approach seems sufficient.
+ return new MethodInvocation(
+ new ListLiteral(elements)..fileOffset = charOffset,
+ new Name("toList"),
+ new Arguments(<Expression>[], named: <NamedExpression>[
+ new NamedExpression("growable", new BoolLiteral(false))
+ ]));
+ }
}
« no previous file with comments | « pkg/kernel/lib/target/targets.dart ('k') | pkg/kernel/lib/transformations/mixin_full_resolution.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698