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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2755953002: Revert "[Fasta] Do not emit default arguments at callsite" (Closed)
Patch Set: Created 3 years, 9 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 | pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.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 library fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import '../parser/parser.dart' show FormalParameterType, optional; 7 import '../parser/parser.dart' show FormalParameterType, optional;
8 8
9 import '../parser/error_kind.dart' show ErrorKind; 9 import '../parser/error_kind.dart' show ErrorKind;
10 10
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 push(name); 1615 push(name);
1616 } 1616 }
1617 1617
1618 @override 1618 @override
1619 Expression buildStaticInvocation(Member target, Arguments arguments, 1619 Expression buildStaticInvocation(Member target, Arguments arguments,
1620 {bool isConst: false, int charOffset: -1}) { 1620 {bool isConst: false, int charOffset: -1}) {
1621 List<TypeParameter> typeParameters = target.function.typeParameters; 1621 List<TypeParameter> typeParameters = target.function.typeParameters;
1622 if (target is Constructor) { 1622 if (target is Constructor) {
1623 typeParameters = target.enclosingClass.typeParameters; 1623 typeParameters = target.enclosingClass.typeParameters;
1624 } 1624 }
1625 if (!checkArguments(target.function, arguments, typeParameters)) { 1625 if (!addDefaultArguments(target.function, arguments, typeParameters)) {
1626 return throwNoSuchMethodError(target.name.name, arguments, charOffset); 1626 return throwNoSuchMethodError(target.name.name, arguments, charOffset);
1627 } 1627 }
1628 if (target is Constructor) { 1628 if (target is Constructor) {
1629 return new ConstructorInvocation(target, arguments)..isConst = isConst; 1629 return new ConstructorInvocation(target, arguments)..isConst = isConst;
1630 } else { 1630 } else {
1631 return new StaticInvocation(target, arguments)..isConst = isConst; 1631 return new StaticInvocation(target, arguments)..isConst = isConst;
1632 } 1632 }
1633 } 1633 }
1634 1634
1635 bool checkArguments(FunctionNode function, Arguments arguments, 1635 bool addDefaultArguments(FunctionNode function, Arguments arguments,
1636 List<TypeParameter> typeParameters) { 1636 List<TypeParameter> typeParameters) {
1637 bool missingInitializers = false;
1638
1639 Expression defaultArgumentFrom(Expression expression) {
1640 if (expression == null) {
1641 missingInitializers = true;
1642 return null;
1643 }
1644 cloner ??= new CloneVisitor();
1645 return cloner.clone(expression);
1646 }
1637 1647
1638 if (arguments.positional.length < function.requiredParameterCount || 1648 if (arguments.positional.length < function.requiredParameterCount ||
1639 arguments.positional.length > function.positionalParameters.length) { 1649 arguments.positional.length > function.positionalParameters.length) {
1640 return false; 1650 return false;
1641 } 1651 }
1652 for (int i = arguments.positional.length;
1653 i < function.positionalParameters.length;
1654 i++) {
1655 var expression =
1656 defaultArgumentFrom(function.positionalParameters[i].initializer);
1657 expression?.parent = arguments;
1658 arguments.positional.add(expression);
1659 }
1642 Map<String, VariableDeclaration> names; 1660 Map<String, VariableDeclaration> names;
1643 if (function.namedParameters.isNotEmpty) { 1661 if (function.namedParameters.isNotEmpty) {
1644 names = <String, VariableDeclaration>{}; 1662 names = <String, VariableDeclaration>{};
1645 for (VariableDeclaration parameter in function.namedParameters) { 1663 for (VariableDeclaration parameter in function.namedParameters) {
1646 names[parameter.name] = parameter; 1664 names[parameter.name] = parameter;
1647 } 1665 }
1648 } 1666 }
1649 if (arguments.named.isNotEmpty) { 1667 if (arguments.named.isNotEmpty) {
1650 if (names == null) return false; 1668 if (names == null) return false;
1651 for (NamedExpression argument in arguments.named) { 1669 for (NamedExpression argument in arguments.named) {
1652 VariableDeclaration parameter = names.remove(argument.name); 1670 VariableDeclaration parameter = names.remove(argument.name);
1653 if (parameter == null) { 1671 if (parameter == null) {
1654 return false; 1672 return false;
1655 } 1673 }
1656 } 1674 }
1657 } 1675 }
1676 if (names != null) {
1677 for (String name in names.keys) {
1678 VariableDeclaration parameter = names[name];
1679 arguments.named.add(new NamedExpression(
1680 name, defaultArgumentFrom(parameter.initializer))
1681 ..parent = arguments);
1682 }
1683 }
1658 if (typeParameters.length != arguments.types.length) { 1684 if (typeParameters.length != arguments.types.length) {
1659 arguments.types.clear(); 1685 arguments.types.clear();
1660 for (int i = 0; i < typeParameters.length; i++) { 1686 for (int i = 0; i < typeParameters.length; i++) {
1661 arguments.types.add(const DynamicType()); 1687 arguments.types.add(const DynamicType());
1662 } 1688 }
1663 } 1689 }
1664 1690
1691 if (missingInitializers) {
1692 library.addArgumentsWithMissingDefaultValues(arguments, function);
1693 }
1665 return true; 1694 return true;
1666 } 1695 }
1667 1696
1668 @override 1697 @override
1669 void handleNewExpression(Token token) { 1698 void handleNewExpression(Token token) {
1670 debugEvent("NewExpression"); 1699 debugEvent("NewExpression");
1671 Arguments arguments = pop(); 1700 Arguments arguments = pop();
1672 String name = pop(); 1701 String name = pop();
1673 List<DartType> typeArguments = pop(); 1702 List<DartType> typeArguments = pop();
1674 var type = pop(); 1703 var type = pop();
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 } else if (node is PrefixBuilder) { 2778 } else if (node is PrefixBuilder) {
2750 return node.name; 2779 return node.name;
2751 } else if (node is ThisAccessor) { 2780 } else if (node is ThisAccessor) {
2752 return node.isSuper ? "super" : "this"; 2781 return node.isSuper ? "super" : "this";
2753 } else if (node is BuilderAccessor) { 2782 } else if (node is BuilderAccessor) {
2754 return node.plainNameForRead; 2783 return node.plainNameForRead;
2755 } else { 2784 } else {
2756 return internalError("Unhandled: ${node.runtimeType}"); 2785 return internalError("Unhandled: ${node.runtimeType}");
2757 } 2786 }
2758 } 2787 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698