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

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
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;
floitsch 2012/01/31 15:52:41 indent by 4?
ngeoffray 2012/01/31 16:46:17 Done.
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 }
Lasse Reichstein Nielsen 2012/01/31 15:36:05 Remove the name from the set, so you don't allow d
ngeoffray 2012/01/31 16:46:17 Done. I expect another phase to check that though.
100 } 115 }
101 return true; 116 return true;
102 } 117 }
103 } 118 }
104 119
105 120
106 static bool sameNames(List<SourceString> first, List<SourceString> second) { 121 static bool sameNames(List<SourceString> first, List<SourceString> second) {
107 for (int i = 0; i < first.length; i++) { 122 for (int i = 0; i < first.length; i++) {
108 return first[i] == second[i]; 123 return first[i] == second[i];
109 } 124 }
110 return true; 125 return true;
111 } 126 }
112 127
113 bool operator ==(other) { 128 bool operator ==(other) {
114 if (other is !Invocation) return false; 129 if (other is !Invocation) return false;
115 return argumentCount == other.argumentCount 130 return argumentCount == other.argumentCount
116 && namedArguments.length == other.namedArguments.length 131 && namedArguments.length == other.namedArguments.length
117 && sameNames(namedArguments, other.namedArguments); 132 && sameNames(namedArguments, other.namedArguments);
118 } 133 }
119 } 134 }
120 135
121 class Invocation extends Selector { 136 class Invocation extends Selector {
122 final List<SourceString> namedArguments; 137 final List<SourceString> namedArguments;
138 int get namedArgumentCount() => namedArguments.length;
139 int get positionalArgumentCount() => argumentCount - namedArgumentCount;
123 140
124 const Invocation( 141 const Invocation(
125 int argumentCount, 142 int argumentCount,
126 [List<SourceString> this.namedArguments = const <SourceString>[]]) 143 [List<SourceString> this.namedArguments = const <SourceString>[]])
127 : super(SelectorKind.INVOCATION, argumentCount); 144 : super(SelectorKind.INVOCATION, argumentCount);
128 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698