| OLD | NEW |
| 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 #library('universe'); | 5 #library('universe'); |
| 6 | 6 |
| 7 #import('../closure.dart'); | 7 #import('../closure.dart'); |
| 8 #import('../elements/elements.dart'); | 8 #import('../elements/elements.dart'); |
| 9 #import('../leg.dart'); | 9 #import('../leg.dart'); |
| 10 #import('../scanner/scannerlib.dart'); | 10 #import('../scanner/scannerlib.dart'); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 if (isGetter()) return true; | 200 if (isGetter()) return true; |
| 201 | 201 |
| 202 FunctionElement function = element; | 202 FunctionElement function = element; |
| 203 FunctionSignature parameters = function.computeSignature(compiler); | 203 FunctionSignature parameters = function.computeSignature(compiler); |
| 204 if (argumentCount > parameters.parameterCount) return false; | 204 if (argumentCount > parameters.parameterCount) return false; |
| 205 int requiredParameterCount = parameters.requiredParameterCount; | 205 int requiredParameterCount = parameters.requiredParameterCount; |
| 206 int optionalParameterCount = parameters.optionalParameterCount; | 206 int optionalParameterCount = parameters.optionalParameterCount; |
| 207 if (positionalArgumentCount < requiredParameterCount) return false; | 207 if (positionalArgumentCount < requiredParameterCount) return false; |
| 208 | 208 |
| 209 if (!parameters.optionalParametersAreNamed) { | 209 if (!parameters.optionalParametersAreNamed) { |
| 210 // TODO(5074): Remove this check once we don't accept the |
| 211 // deprecated parameter specification. |
| 210 if (!Compiler.REJECT_NAMED_ARGUMENT_AS_POSITIONAL) { | 212 if (!Compiler.REJECT_NAMED_ARGUMENT_AS_POSITIONAL) { |
| 211 return optionalParametersAppliesDEPRECATED(element, compiler); | 213 return optionalParametersAppliesDEPRECATED(element, compiler); |
| 212 } else { | 214 } else { |
| 213 // We have already checked that the number of arguments are | 215 // We have already checked that the number of arguments are |
| 214 // not greater than the number of parameters. Therefore the | 216 // not greater than the number of parameters. Therefore the |
| 215 // number of positional arguments are not greater than the | 217 // number of positional arguments are not greater than the |
| 216 // number of parameters. | 218 // number of parameters. |
| 217 assert(positionalArgumentCount <= parameters.parameterCount); | 219 assert(positionalArgumentCount <= parameters.parameterCount); |
| 218 return namedArguments.isEmpty(); | 220 return namedArguments.isEmpty(); |
| 219 } | 221 } |
| 220 } else { | 222 } else { |
| 221 if (positionalArgumentCount > requiredParameterCount) return false; | 223 if (positionalArgumentCount > requiredParameterCount) return false; |
| 224 assert(positionalArgumentCount == requiredParameterCount); |
| 222 if (namedArgumentCount > optionalParameterCount) return false; | 225 if (namedArgumentCount > optionalParameterCount) return false; |
| 223 Set<SourceString> nameSet = new Set<SourceString>(); | 226 Set<SourceString> nameSet = new Set<SourceString>(); |
| 224 parameters.optionalParameters.forEach((Element element) { | 227 parameters.optionalParameters.forEach((Element element) { |
| 225 nameSet.add(element.name); | 228 nameSet.add(element.name); |
| 226 }); | 229 }); |
| 227 for (SourceString name in namedArguments) { | 230 for (SourceString name in namedArguments) { |
| 228 if (!nameSet.contains(name)) return false; | 231 if (!nameSet.contains(name)) return false; |
| 229 // TODO(ngeoffray): By removing from the set we are checking | 232 // TODO(5213): By removing from the set we are checking |
| 230 // that we are not passing the name twice. We should have this | 233 // that we are not passing the name twice. We should have this |
| 231 // check in the resolver instead. | 234 // check in the resolver also. |
| 232 nameSet.remove(name); | 235 nameSet.remove(name); |
| 233 } | 236 } |
| 234 return true; | 237 return true; |
| 235 } | 238 } |
| 236 } | 239 } |
| 237 | 240 |
| 238 // TODO(5074): Remove this method once we don't accept the | 241 // TODO(5074): Remove this method once we don't accept the |
| 239 // deprecated parameter specification. | 242 // deprecated parameter specification. |
| 240 bool optionalParametersAppliesDEPRECATED(FunctionElement function, | 243 bool optionalParametersAppliesDEPRECATED(FunctionElement function, |
| 241 Compiler compiler) { | 244 Compiler compiler) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 Compiler compiler) { | 341 Compiler compiler) { |
| 339 if (!this.applies(element, compiler)) return false; | 342 if (!this.applies(element, compiler)) return false; |
| 340 | 343 |
| 341 FunctionSignature parameters = element.computeSignature(compiler); | 344 FunctionSignature parameters = element.computeSignature(compiler); |
| 342 parameters.forEachRequiredParameter((element) { | 345 parameters.forEachRequiredParameter((element) { |
| 343 list.add(compileArgument(arguments.head)); | 346 list.add(compileArgument(arguments.head)); |
| 344 arguments = arguments.tail; | 347 arguments = arguments.tail; |
| 345 }); | 348 }); |
| 346 | 349 |
| 347 if (!parameters.optionalParametersAreNamed) { | 350 if (!parameters.optionalParametersAreNamed) { |
| 351 // TODO(5074): Remove this check once we don't accept the |
| 352 // deprecated parameter specification. |
| 348 if (!Compiler.REJECT_NAMED_ARGUMENT_AS_POSITIONAL) { | 353 if (!Compiler.REJECT_NAMED_ARGUMENT_AS_POSITIONAL) { |
| 349 addOptionalArgumentsToListDEPRECATED( | 354 addOptionalArgumentsToListDEPRECATED( |
| 350 arguments, list, element, compileArgument, compileConstant, | 355 arguments, list, element, compileArgument, compileConstant, |
| 351 compiler); | 356 compiler); |
| 352 } else { | 357 } else { |
| 353 parameters.forEachOptionalParameter((element) { | 358 parameters.forEachOptionalParameter((element) { |
| 354 if (!arguments.isEmpty()) { | 359 if (!arguments.isEmpty()) { |
| 355 list.add(compileArgument(arguments.head)); | 360 list.add(compileArgument(arguments.head)); |
| 356 arguments = arguments.tail; | 361 arguments = arguments.tail; |
| 357 } else { | 362 } else { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 | 496 |
| 492 if (!self.isInterface() && self.isSubclassOf(other)) { | 497 if (!self.isInterface() && self.isSubclassOf(other)) { |
| 493 // Resolve an invocation of [element.name] on [self]. If it | 498 // Resolve an invocation of [element.name] on [self]. If it |
| 494 // is found, this selector is a candidate. | 499 // is found, this selector is a candidate. |
| 495 return hasElementIn(self, element) && appliesUntyped(element, compiler); | 500 return hasElementIn(self, element) && appliesUntyped(element, compiler); |
| 496 } | 501 } |
| 497 | 502 |
| 498 return false; | 503 return false; |
| 499 } | 504 } |
| 500 } | 505 } |
| OLD | NEW |