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

Side by Side Diff: lib/compiler/implementation/universe.dart

Issue 9961005: Verify that there are enough positional arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | « no previous file | tests/language/language-leg.status » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 Map<Element, String> generatedCode; 6 Map<Element, String> generatedCode;
7 Map<Element, String> generatedBailoutCode; 7 Map<Element, String> generatedBailoutCode;
8 final Set<ClassElement> instantiatedClasses; 8 final Set<ClassElement> instantiatedClasses;
9 final Set<SourceString> instantiatedClassInstanceFields; 9 final Set<SourceString> instantiatedClassInstanceFields;
10 final Set<FunctionElement> staticFunctionsNeedingGetter; 10 final Set<FunctionElement> staticFunctionsNeedingGetter;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 static final SelectorKind GETTER = const SelectorKind('getter'); 42 static final SelectorKind GETTER = const SelectorKind('getter');
43 static final SelectorKind SETTER = const SelectorKind('setter'); 43 static final SelectorKind SETTER = const SelectorKind('setter');
44 static final SelectorKind INVOCATION = const SelectorKind('invocation'); 44 static final SelectorKind INVOCATION = const SelectorKind('invocation');
45 static final SelectorKind OPERATOR = const SelectorKind('operator'); 45 static final SelectorKind OPERATOR = const SelectorKind('operator');
46 static final SelectorKind INDEX = const SelectorKind('index'); 46 static final SelectorKind INDEX = const SelectorKind('index');
47 47
48 toString() => name; 48 toString() => name;
49 } 49 }
50 50
51 class Selector implements Hashable { 51 class Selector implements Hashable {
52 // The numbers of arguments of the selector. Includes named 52 // The numbers of arguments of the selector. Includes named arguments.
53 // arguments.
54 final int argumentCount; 53 final int argumentCount;
55 final SelectorKind kind; 54 final SelectorKind kind;
56 const Selector(this.kind, this.argumentCount); 55 const Selector(this.kind, this.argumentCount);
57 56
58 int hashCode() => argumentCount + 1000 * namedArguments.length; 57 int hashCode() => argumentCount + 1000 * namedArguments.length;
59 List<SourceString> get namedArguments() => const <SourceString>[]; 58 List<SourceString> get namedArguments() => const <SourceString>[];
60 int get namedArgumentCount() => 0; 59 int get namedArgumentCount() => 0;
61 int get positionalArgumentCount() => argumentCount; 60 int get positionalArgumentCount() => argumentCount;
62 61
63 static final Selector GETTER = const Selector(SelectorKind.GETTER, 0); 62 static final Selector GETTER = const Selector(SelectorKind.GETTER, 0);
(...skipping 12 matching lines...) Expand all
76 const Selector(SelectorKind.INVOCATION, 0); 75 const Selector(SelectorKind.INVOCATION, 0);
77 static final Selector INVOCATION_1 = 76 static final Selector INVOCATION_1 =
78 const Selector(SelectorKind.INVOCATION, 1); 77 const Selector(SelectorKind.INVOCATION, 1);
79 static final Selector INVOCATION_2 = 78 static final Selector INVOCATION_2 =
80 const Selector(SelectorKind.INVOCATION, 2); 79 const Selector(SelectorKind.INVOCATION, 2);
81 80
82 bool applies(FunctionParameters parameters) { 81 bool applies(FunctionParameters parameters) {
83 if (argumentCount > parameters.parameterCount) return false; 82 if (argumentCount > parameters.parameterCount) return false;
84 int requiredParameterCount = parameters.requiredParameterCount; 83 int requiredParameterCount = parameters.requiredParameterCount;
85 int optionalParameterCount = parameters.optionalParameterCount; 84 int optionalParameterCount = parameters.optionalParameterCount;
85 if (positionalArgumentCount < requiredParameterCount) return false;
86 86
87 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); 87 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty();
88 if (namedArguments.isEmpty()) { 88 if (namedArguments.isEmpty()) {
89 if (!hasOptionalParameters) { 89 if (!hasOptionalParameters) {
90 return requiredParameterCount == argumentCount; 90 return requiredParameterCount == argumentCount;
91 } else { 91 } else {
92 return argumentCount >= requiredParameterCount && 92 return argumentCount >= requiredParameterCount &&
93 argumentCount <= requiredParameterCount + optionalParameterCount; 93 argumentCount <= requiredParameterCount + optionalParameterCount;
94 } 94 }
95 } else { 95 } else {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments; 225 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments;
226 226
227 List<SourceString> list = new List<SourceString>.from(namedArguments); 227 List<SourceString> list = new List<SourceString>.from(namedArguments);
228 list.sort((SourceString first, SourceString second) { 228 list.sort((SourceString first, SourceString second) {
229 return first.slowToString().compareTo(second.slowToString()); 229 return first.slowToString().compareTo(second.slowToString());
230 }); 230 });
231 orderedNamedArguments = list; 231 orderedNamedArguments = list;
232 return orderedNamedArguments; 232 return orderedNamedArguments;
233 } 233 }
234 } 234 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698