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

Side by Side Diff: frog/leg/universe.dart

Issue 9301038: Support named arguments for statically resolved calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « frog/leg/ssa/codegen.dart ('k') | frog/tests/leg_only/src/NamedParameterForStaticTest.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 class Universe { 5 class Universe {
6 final Element scope; 6 final Element scope;
7 7
8 Map<SourceString, Element> elements; 8 Map<SourceString, Element> elements;
9 Map<Element, String> generatedCode; 9 Map<Element, String> generatedCode;
10 Map<Element, String> generatedBailoutCode; 10 Map<Element, String> generatedBailoutCode;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 class Selector implements Hashable { 58 class Selector implements Hashable {
59 // The numbers of arguments of the selector. Includes named 59 // The numbers of arguments of the selector. Includes named
60 // arguments. 60 // arguments.
61 final int argumentCount; 61 final int argumentCount;
62 final SelectorKind kind; 62 final SelectorKind kind;
63 const Selector(this.kind, this.argumentCount); 63 const Selector(this.kind, this.argumentCount);
64 64
65 int hashCode() => argumentCount + 1000 * namedArguments.length; 65 int hashCode() => argumentCount + 1000 * namedArguments.length;
66 List<SourceString> get namedArguments() => const <SourceString>[]; 66 List<SourceString> get namedArguments() => const <SourceString>[];
67 int get namedArgumentCount() => 0;
68 int get positionalArgumentCount() => argumentCount;
67 69
68 static final Selector GETTER = const Selector(SelectorKind.GETTER, 0); 70 static final Selector GETTER = const Selector(SelectorKind.GETTER, 0);
69 static final Selector SETTER = const Selector(SelectorKind.SETTER, 1); 71 static final Selector SETTER = const Selector(SelectorKind.SETTER, 1);
70 static final Selector UNARY_OPERATOR = 72 static final Selector UNARY_OPERATOR =
71 const Selector(SelectorKind.OPERATOR, 0); 73 const Selector(SelectorKind.OPERATOR, 0);
72 static final Selector BINARY_OPERATOR = 74 static final Selector BINARY_OPERATOR =
73 const Selector(SelectorKind.OPERATOR, 1); 75 const Selector(SelectorKind.OPERATOR, 1);
74 static final Selector INDEX = const Selector(SelectorKind.INDEX, 1); 76 static final Selector INDEX = const Selector(SelectorKind.INDEX, 1);
75 static final Selector INDEX_SET = const Selector(SelectorKind.INDEX, 2); 77 static final Selector INDEX_SET = const Selector(SelectorKind.INDEX, 2);
76 static final Selector INDEX_AND_INDEX_SET = 78 static final Selector INDEX_AND_INDEX_SET =
77 const Selector(SelectorKind.INDEX, 2); 79 const Selector(SelectorKind.INDEX, 2);
78 static final Selector GETTER_AND_SETTER = 80 static final Selector GETTER_AND_SETTER =
79 const Selector(SelectorKind.SETTER, 1); 81 const Selector(SelectorKind.SETTER, 1);
80 static final Selector INVOCATION_0 = const Invocation(0); 82 static final Selector INVOCATION_0 = const Invocation(0);
81 83
82 bool applies(Compiler compiler, FunctionElement element) { 84 bool applies(Compiler compiler, FunctionElement element) {
83 FunctionParameters parameters = element.computeParameters(compiler); 85 FunctionParameters parameters = element.computeParameters(compiler);
84 int parameterCount = parameters.parameterCount; 86 if (argumentCount > parameters.parameterCount) return false;
85 if (argumentCount > parameterCount) return false; 87 int requiredParameterCount = parameters.requiredParameterCount;
88 int optionalParameterCount = parameters.optionalParameterCount;
86 89
87 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); 90 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty();
88 if (namedArguments.isEmpty()) { 91 if (namedArguments.isEmpty()) {
89 if (!hasOptionalParameters) { 92 if (!hasOptionalParameters) {
90 return parameterCount == argumentCount; 93 return requiredParameterCount == argumentCount;
91 } else { 94 } else {
92 int optionalParameterCount = parameters.optionalParameterCount; 95 return argumentCount >= requiredParameterCount &&
93 return argumentCount >= parameterCount && 96 argumentCount <= requiredParameterCount + optionalParameterCount;
94 argumentCount <= parameterCount + optionalParameterCount;
95 } 97 }
96 } else { 98 } else {
97 if (!hasOptionalParameters) return false; 99 if (!hasOptionalParameters) return false;
100 Link<Element> remainingNamedParameters = parameters.optionalParameters;
101 for (int i = requiredParameterCount; i < positionalArgumentCount; i++) {
102 remainingNamedParameters = remainingNamedParameters.tail;
103 }
104 Set<SourceString> nameSet = new Set<SourceString>();
105 for (;
106 !remainingNamedParameters.isEmpty();
107 remainingNamedParameters = remainingNamedParameters.tail) {
108 nameSet.add(remainingNamedParameters.head.name);
109 }
110
98 for (SourceString name in namedArguments) { 111 for (SourceString name in namedArguments) {
99 compiler.cancel('unimplemented named constructors'); 112 if (!nameSet.contains(name)) {
113 return false;
114 }
115 nameSet.remove(name);
100 } 116 }
101 return true; 117 return true;
102 } 118 }
103 } 119 }
104 120
105 121
106 static bool sameNames(List<SourceString> first, List<SourceString> second) { 122 static bool sameNames(List<SourceString> first, List<SourceString> second) {
107 for (int i = 0; i < first.length; i++) { 123 for (int i = 0; i < first.length; i++) {
108 return first[i] == second[i]; 124 return first[i] == second[i];
109 } 125 }
110 return true; 126 return true;
111 } 127 }
112 128
113 bool operator ==(other) { 129 bool operator ==(other) {
114 if (other is !Invocation) return false; 130 if (other is !Invocation) return false;
115 return argumentCount == other.argumentCount 131 return argumentCount == other.argumentCount
116 && namedArguments.length == other.namedArguments.length 132 && namedArguments.length == other.namedArguments.length
117 && sameNames(namedArguments, other.namedArguments); 133 && sameNames(namedArguments, other.namedArguments);
118 } 134 }
119 } 135 }
120 136
121 class Invocation extends Selector { 137 class Invocation extends Selector {
122 final List<SourceString> namedArguments; 138 final List<SourceString> namedArguments;
139 int get namedArgumentCount() => namedArguments.length;
140 int get positionalArgumentCount() => argumentCount - namedArgumentCount;
123 141
124 const Invocation( 142 const Invocation(
125 int argumentCount, 143 int argumentCount,
126 [List<SourceString> this.namedArguments = const <SourceString>[]]) 144 [List<SourceString> this.namedArguments = const <SourceString>[]])
127 : super(SelectorKind.INVOCATION, argumentCount); 145 : super(SelectorKind.INVOCATION, argumentCount);
128 } 146 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/codegen.dart ('k') | frog/tests/leg_only/src/NamedParameterForStaticTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698