| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 static final Selector UNARY_OPERATOR = | 72 static final Selector UNARY_OPERATOR = |
| 73 const Selector(SelectorKind.OPERATOR, 0); | 73 const Selector(SelectorKind.OPERATOR, 0); |
| 74 static final Selector BINARY_OPERATOR = | 74 static final Selector BINARY_OPERATOR = |
| 75 const Selector(SelectorKind.OPERATOR, 1); | 75 const Selector(SelectorKind.OPERATOR, 1); |
| 76 static final Selector INDEX = const Selector(SelectorKind.INDEX, 1); | 76 static final Selector INDEX = const Selector(SelectorKind.INDEX, 1); |
| 77 static final Selector INDEX_SET = const Selector(SelectorKind.INDEX, 2); | 77 static final Selector INDEX_SET = const Selector(SelectorKind.INDEX, 2); |
| 78 static final Selector INDEX_AND_INDEX_SET = | 78 static final Selector INDEX_AND_INDEX_SET = |
| 79 const Selector(SelectorKind.INDEX, 2); | 79 const Selector(SelectorKind.INDEX, 2); |
| 80 static final Selector GETTER_AND_SETTER = | 80 static final Selector GETTER_AND_SETTER = |
| 81 const Selector(SelectorKind.SETTER, 1); | 81 const Selector(SelectorKind.SETTER, 1); |
| 82 static final Selector INVOCATION_0 = const Invocation(0); | 82 static final Selector INVOCATION_0 = |
| 83 const Selector(SelectorKind.INVOCATION, 0); |
| 83 | 84 |
| 84 bool applies(Compiler compiler, FunctionElement element) { | 85 bool applies(Compiler compiler, FunctionElement element) { |
| 85 FunctionParameters parameters = element.computeParameters(compiler); | 86 FunctionParameters parameters = element.computeParameters(compiler); |
| 86 if (argumentCount > parameters.parameterCount) return false; | 87 if (argumentCount > parameters.parameterCount) return false; |
| 87 int requiredParameterCount = parameters.requiredParameterCount; | 88 int requiredParameterCount = parameters.requiredParameterCount; |
| 88 int optionalParameterCount = parameters.optionalParameterCount; | 89 int optionalParameterCount = parameters.optionalParameterCount; |
| 89 | 90 |
| 90 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); | 91 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); |
| 91 if (namedArguments.isEmpty()) { | 92 if (namedArguments.isEmpty()) { |
| 92 if (!hasOptionalParameters) { | 93 if (!hasOptionalParameters) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 126 } |
| 126 return true; | 127 return true; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool operator ==(other) { | 130 bool operator ==(other) { |
| 130 if (other is !Invocation) return false; | 131 if (other is !Invocation) return false; |
| 131 return argumentCount == other.argumentCount | 132 return argumentCount == other.argumentCount |
| 132 && namedArguments.length == other.namedArguments.length | 133 && namedArguments.length == other.namedArguments.length |
| 133 && sameNames(namedArguments, other.namedArguments); | 134 && sameNames(namedArguments, other.namedArguments); |
| 134 } | 135 } |
| 136 |
| 137 void set orderedNamedArguments(List<SourceString> other) { |
| 138 // It's ok to ignore [other] if it's empty because this type of |
| 139 // selector should not have any named arguments. |
| 140 assert(other.isEmpty()); |
| 141 } |
| 142 |
| 143 String toString() => '$argumentCount'; |
| 135 } | 144 } |
| 136 | 145 |
| 137 class Invocation extends Selector { | 146 class Invocation extends Selector { |
| 138 final List<SourceString> namedArguments; | 147 final List<SourceString> namedArguments; |
| 148 List<SourceString> orderedNamedArguments; |
| 139 int get namedArgumentCount() => namedArguments.length; | 149 int get namedArgumentCount() => namedArguments.length; |
| 140 int get positionalArgumentCount() => argumentCount - namedArgumentCount; | 150 int get positionalArgumentCount() => argumentCount - namedArgumentCount; |
| 141 | 151 |
| 142 const Invocation( | 152 Invocation(int argumentCount, |
| 143 int argumentCount, | 153 [List<SourceString> this.namedArguments = const <SourceString>[]]) |
| 144 [List<SourceString> this.namedArguments = const <SourceString>[]]) | 154 : super(SelectorKind.INVOCATION, argumentCount), |
| 145 : super(SelectorKind.INVOCATION, argumentCount); | 155 orderedNamedArguments = const <SourceString>[]; |
| 156 |
| 157 String toString() { |
| 158 StringBuffer buffer = new StringBuffer(); |
| 159 for (SourceString name in orderedNamedArguments) { |
| 160 buffer.add('\$$name'); |
| 161 } |
| 162 return '$argumentCount$buffer'; |
| 163 } |
| 146 } | 164 } |
| OLD | NEW |