Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /// ----------------------------------------------------------------------- | 5 /// ----------------------------------------------------------------------- |
| 6 /// ERROR HANDLING | 6 /// ERROR HANDLING |
| 7 /// ----------------------------------------------------------------------- | 7 /// ----------------------------------------------------------------------- |
| 8 /// | 8 /// |
| 9 /// As a rule of thumb, errors that can be detected statically are handled by | 9 /// As a rule of thumb, errors that can be detected statically are handled by |
| 10 /// the frontend, typically by translating the erroneous code into a 'throw' or | 10 /// the frontend, typically by translating the erroneous code into a 'throw' or |
| (...skipping 3973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3984 /// | 3984 /// |
| 3985 /// Any uses of its type parameters become free variables in the returned | 3985 /// Any uses of its type parameters become free variables in the returned |
| 3986 /// type. | 3986 /// type. |
| 3987 FunctionType get withoutTypeParameters { | 3987 FunctionType get withoutTypeParameters { |
| 3988 if (typeParameters.isEmpty) return this; | 3988 if (typeParameters.isEmpty) return this; |
| 3989 return new FunctionType(positionalParameters, returnType, | 3989 return new FunctionType(positionalParameters, returnType, |
| 3990 requiredParameterCount: requiredParameterCount, | 3990 requiredParameterCount: requiredParameterCount, |
| 3991 namedParameters: namedParameters); | 3991 namedParameters: namedParameters); |
| 3992 } | 3992 } |
| 3993 | 3993 |
| 3994 /// Looks up the type of the named parameter with the given name. | |
| 3995 /// | |
| 3996 /// Returns `null` if there is no named parameter with the given name. | |
| 3997 DartType getNamedParameter(String name) { | |
| 3998 int lower = 0; | |
| 3999 int upper = namedParameters.length - 1; | |
| 4000 while (lower <= upper) { | |
| 4001 int pivot = (lower + upper) ~/ 2; | |
| 4002 int comparison = name.compareTo(namedParameters[pivot].name); | |
|
scheglov
2017/05/10 18:03:35
It should be slightly faster to extract `namedPara
Paul Berry
2017/05/10 18:16:08
Done.
| |
| 4003 if (comparison == 0) { | |
| 4004 return namedParameters[pivot].type; | |
| 4005 } else if (comparison < 0) { | |
| 4006 upper = pivot - 1; | |
| 4007 } else { | |
| 4008 lower = pivot + 1; | |
| 4009 } | |
| 4010 } | |
| 4011 return null; | |
| 4012 } | |
| 4013 | |
| 3994 int get hashCode => _hashCode ??= _computeHashCode(); | 4014 int get hashCode => _hashCode ??= _computeHashCode(); |
| 3995 | 4015 |
| 3996 int _computeHashCode() { | 4016 int _computeHashCode() { |
| 3997 int hash = 1237; | 4017 int hash = 1237; |
| 3998 hash = 0x3fffffff & (hash * 31 + requiredParameterCount); | 4018 hash = 0x3fffffff & (hash * 31 + requiredParameterCount); |
| 3999 for (int i = 0; i < typeParameters.length; ++i) { | 4019 for (int i = 0; i < typeParameters.length; ++i) { |
| 4000 TypeParameter parameter = typeParameters[i]; | 4020 TypeParameter parameter = typeParameters[i]; |
| 4001 _temporaryHashCodeTable[parameter] = _temporaryHashCodeTable.length; | 4021 _temporaryHashCodeTable[parameter] = _temporaryHashCodeTable.length; |
| 4002 hash = 0x3fffffff & (hash * 31 + parameter.bound.hashCode); | 4022 hash = 0x3fffffff & (hash * 31 + parameter.bound.hashCode); |
| 4003 } | 4023 } |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4480 /// typedef has not been assigned a canonical name yet. | 4500 /// typedef has not been assigned a canonical name yet. |
| 4481 /// | 4501 /// |
| 4482 /// Returns `null` if the typedef is `null`. | 4502 /// Returns `null` if the typedef is `null`. |
| 4483 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { | 4503 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { |
| 4484 if (typedef_ == null) return null; | 4504 if (typedef_ == null) return null; |
| 4485 if (typedef_.canonicalName == null) { | 4505 if (typedef_.canonicalName == null) { |
| 4486 throw '$typedef_ has no canonical name'; | 4506 throw '$typedef_ has no canonical name'; |
| 4487 } | 4507 } |
| 4488 return typedef_.canonicalName; | 4508 return typedef_.canonicalName; |
| 4489 } | 4509 } |
| OLD | NEW |