| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.target.vm; | 4 library kernel.target.vm; |
| 5 | 5 |
| 6 import '../ast.dart'; | 6 import '../ast.dart'; |
| 7 import '../class_hierarchy.dart'; | 7 import '../class_hierarchy.dart'; |
| 8 import '../core_types.dart'; | 8 import '../core_types.dart'; |
| 9 import '../transformations/continuation.dart' as cont; | 9 import '../transformations/continuation.dart' as cont; |
| 10 import '../transformations/erasure.dart'; | 10 import '../transformations/erasure.dart'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 'dart:vmservice_io', | 50 'dart:vmservice_io', |
| 51 'dart:_vmservice', | 51 'dart:_vmservice', |
| 52 'dart:_builtin', | 52 'dart:_builtin', |
| 53 'dart:nativewrappers', | 53 'dart:nativewrappers', |
| 54 'dart:io', | 54 'dart:io', |
| 55 ]; | 55 ]; |
| 56 | 56 |
| 57 ClassHierarchy _hierarchy; | 57 ClassHierarchy _hierarchy; |
| 58 | 58 |
| 59 void performModularTransformations(Program program) { | 59 void performModularTransformations(Program program) { |
| 60 var mixins = new mix.MixinFullResolution()..transform(program); | 60 var mixins = new mix.MixinFullResolution(this)..transform(program); |
| 61 | 61 |
| 62 _hierarchy = mixins.hierarchy; | 62 _hierarchy = mixins.hierarchy; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void performGlobalTransformations(Program program) { | 65 void performGlobalTransformations(Program program) { |
| 66 var coreTypes = new CoreTypes(program); | 66 var coreTypes = new CoreTypes(program); |
| 67 | 67 |
| 68 if (strongMode) { | 68 if (strongMode) { |
| 69 new InsertTypeChecks(hierarchy: _hierarchy, coreTypes: coreTypes) | 69 new InsertTypeChecks(hierarchy: _hierarchy, coreTypes: coreTypes) |
| 70 .transformProgram(program); | 70 .transformProgram(program); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 coreTypes: coreTypes, | 92 coreTypes: coreTypes, |
| 93 strongMode: strongMode, | 93 strongMode: strongMode, |
| 94 programRoots: flags.programRoots) | 94 programRoots: flags.programRoots) |
| 95 .transform(program); | 95 .transform(program); |
| 96 _hierarchy = null; // Hierarchy must be recomputed. | 96 _hierarchy = null; // Hierarchy must be recomputed. |
| 97 } | 97 } |
| 98 | 98 |
| 99 void performErasure(Program program) { | 99 void performErasure(Program program) { |
| 100 new Erasure().transform(program); | 100 new Erasure().transform(program); |
| 101 } | 101 } |
| 102 |
| 103 @override |
| 104 Expression instantiateInvocation(Member target, Expression receiver, |
| 105 String name, Arguments arguments, int offset, bool isSuper) { |
| 106 // See [_InvocationMirror] |
| 107 // (../../../../runtime/lib/invocation_mirror_patch.dart). |
| 108 // The _InvocationMirror constructor takes the following arguments: |
| 109 // * Method name (a string). |
| 110 // * An arguments descriptor - a list consisting of: |
| 111 // - length of passed type argument vector, 0 if none passed. |
| 112 // - number of arguments (including receiver). |
| 113 // - number of positional arguments (including receiver). |
| 114 // - pairs (2 entries in the list) of |
| 115 // * named arguments name. |
| 116 // * index of named argument in arguments list. |
| 117 // * A list of arguments, where the first ones are the positional arguments. |
| 118 // * Whether it's a super invocation or not. |
| 119 |
| 120 int typeArgsLen = 0; // TODO(regis): Type arguments of generic function. |
| 121 int numPositionalArguments = arguments.positional.length; |
| 122 numPositionalArguments++; // Include the receiver. |
| 123 int numArguments = numPositionalArguments + arguments.named.length; |
| 124 List<Expression> argumentsDescriptor = [ |
| 125 new IntLiteral(typeArgsLen)..fileOffset = offset, |
| 126 new IntLiteral(numArguments)..fileOffset = offset, |
| 127 new IntLiteral(numPositionalArguments)..fileOffset = offset, |
| 128 ]; |
| 129 |
| 130 List<Expression> argumentsList = <Expression>[receiver]; |
| 131 argumentsList.addAll(arguments.positional); |
| 132 |
| 133 for (NamedExpression argument in arguments.named) { |
| 134 argumentsDescriptor.add( |
| 135 new StringLiteral(argument.name)..fileOffset = argument.fileOffset); |
| 136 argumentsDescriptor.add(new IntLiteral(argumentsList.length) |
| 137 ..fileOffset = argument.fileOffset); |
| 138 argumentsList.add(argument.value); |
| 139 } |
| 140 |
| 141 Arguments constructorArguments = new Arguments([ |
| 142 new StringLiteral(name)..fileOffset = offset, |
| 143 _fixedLengthList(argumentsDescriptor, arguments.fileOffset), |
| 144 _fixedLengthList(argumentsList, arguments.fileOffset), |
| 145 new BoolLiteral(isSuper)..fileOffset = arguments.fileOffset, |
| 146 ]); |
| 147 |
| 148 return (target is Constructor |
| 149 ? new ConstructorInvocation(target, constructorArguments) |
| 150 : new StaticInvocation(target, constructorArguments)) |
| 151 ..fileOffset = offset; |
| 152 } |
| 153 |
| 154 Expression _fixedLengthList(List<Expression> elements, int charOffset) { |
| 155 // TODO(ahe): It's possible that it would be better to create a fixed-length |
| 156 // list first, and then populate it. That would create fewer objects. But as |
| 157 // this is currently only used in (statically resolved) no-such-method |
| 158 // handling, the current approach seems sufficient. |
| 159 return new MethodInvocation( |
| 160 new ListLiteral(elements)..fileOffset = charOffset, |
| 161 new Name("toList"), |
| 162 new Arguments(<Expression>[], named: <NamedExpression>[ |
| 163 new NamedExpression("growable", new BoolLiteral(false)) |
| 164 ])); |
| 165 } |
| 102 } | 166 } |
| OLD | NEW |