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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2957583003: Fix computation of default values for named parameters. (Closed)
Patch Set: Created 3 years, 6 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 | tests/compiler/dart2js/kernel/compile_from_dill_test.dart » ('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) 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 4
5 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry; 9 import '../common/codegen.dart' show CodegenRegistry;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 namedValues[argument.name] = pop(); 2257 namedValues[argument.name] = pop();
2258 } 2258 }
2259 for (String name in selector.callStructure.getOrderedNamedArguments()) { 2259 for (String name in selector.callStructure.getOrderedNamedArguments()) {
2260 values.add(namedValues[name]); 2260 values.add(namedValues[name]);
2261 } 2261 }
2262 2262
2263 return values; 2263 return values;
2264 } 2264 }
2265 2265
2266 /// Build argument list in canonical order for a static [target], including 2266 /// Build argument list in canonical order for a static [target], including
2267 /// filling in the defaulted argument value. 2267 /// filling in the default argument value.
2268 List<HInstruction> _visitArgumentsForStaticTarget( 2268 List<HInstruction> _visitArgumentsForStaticTarget(
2269 ir.FunctionNode target, ir.Arguments arguments) { 2269 ir.FunctionNode target, ir.Arguments arguments) {
2270 // Visit arguments in source order, then re-order and fill in defaults. 2270 // Visit arguments in source order, then re-order and fill in defaults.
2271 var values = _visitPositionalArguments(arguments); 2271 var values = _visitPositionalArguments(arguments);
2272 2272
2273 while (values.length < target.positionalParameters.length) { 2273 while (values.length < target.positionalParameters.length) {
2274 ir.VariableDeclaration parameter = 2274 ir.VariableDeclaration parameter =
2275 target.positionalParameters[values.length]; 2275 target.positionalParameters[values.length];
2276 values.add(_defaultValueForParameter(parameter)); 2276 values.add(_defaultValueForParameter(parameter));
2277 } 2277 }
2278 2278
2279 if (arguments.named.isNotEmpty) { 2279 if (target.namedParameters.isNotEmpty) {
2280 var namedValues = <String, HInstruction>{}; 2280 var namedValues = <String, HInstruction>{};
2281 for (ir.NamedExpression argument in arguments.named) { 2281 for (ir.NamedExpression argument in arguments.named) {
2282 argument.value.accept(this); 2282 argument.value.accept(this);
2283 namedValues[argument.name] = pop(); 2283 namedValues[argument.name] = pop();
2284 } 2284 }
2285 2285
2286 // Visit named arguments in parameter-position order, selecting provided 2286 // Visit named arguments in parameter-position order, selecting provided
2287 // or default value. 2287 // or default value.
2288 // TODO(sra): Ensure the stored order is canonical so we don't have to 2288 // TODO(sra): Ensure the stored order is canonical so we don't have to
2289 // sort. The old builder uses CallStructure.makeArgumentList which depends 2289 // sort. The old builder uses CallStructure.makeArgumentList which depends
2290 // on the old element model. 2290 // on the old element model.
2291 var namedParameters = target.namedParameters.toList() 2291 var namedParameters = target.namedParameters.toList()
2292 ..sort((ir.VariableDeclaration a, ir.VariableDeclaration b) => 2292 ..sort((ir.VariableDeclaration a, ir.VariableDeclaration b) =>
2293 a.name.compareTo(b.name)); 2293 a.name.compareTo(b.name));
2294 for (ir.VariableDeclaration parameter in namedParameters) { 2294 for (ir.VariableDeclaration parameter in namedParameters) {
2295 HInstruction value = namedValues[parameter.name]; 2295 HInstruction value = namedValues[parameter.name];
2296 if (value == null) { 2296 if (value == null) {
2297 values.add(_defaultValueForParameter(parameter)); 2297 values.add(_defaultValueForParameter(parameter));
2298 } else { 2298 } else {
2299 values.add(value); 2299 values.add(value);
2300 namedValues.remove(parameter.name); 2300 namedValues.remove(parameter.name);
2301 } 2301 }
2302 } 2302 }
2303 assert(namedValues.isEmpty); 2303 assert(namedValues.isEmpty);
2304 } else {
2305 assert(arguments.named.isEmpty);
2304 } 2306 }
2305 2307
2306 return values; 2308 return values;
2307 } 2309 }
2308 2310
2309 void _addTypeArguments(List<HInstruction> values, ir.Arguments arguments) { 2311 void _addTypeArguments(List<HInstruction> values, ir.Arguments arguments) {
2310 // need to translate type to 2312 // need to translate type to
2311 for (ir.DartType type in arguments.types) { 2313 for (ir.DartType type in arguments.types) {
2312 values.add(typeBuilder.analyzeTypeArgument( 2314 values.add(typeBuilder.analyzeTypeArgument(
2313 _elementMap.getDartType(type), sourceElement)); 2315 _elementMap.getDartType(type), sourceElement));
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
3496 enterBlock.setBlockFlow( 3498 enterBlock.setBlockFlow(
3497 new HTryBlockInformation( 3499 new HTryBlockInformation(
3498 kernelBuilder.wrapStatementGraph(bodyGraph), 3500 kernelBuilder.wrapStatementGraph(bodyGraph),
3499 exception, 3501 exception,
3500 kernelBuilder.wrapStatementGraph(catchGraph), 3502 kernelBuilder.wrapStatementGraph(catchGraph),
3501 kernelBuilder.wrapStatementGraph(finallyGraph)), 3503 kernelBuilder.wrapStatementGraph(finallyGraph)),
3502 exitBlock); 3504 exitBlock);
3503 kernelBuilder.inTryStatement = previouslyInTryStatement; 3505 kernelBuilder.inTryStatement = previouslyInTryStatement;
3504 } 3506 }
3505 } 3507 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/kernel/compile_from_dill_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698