| 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 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 const Selector(SelectorKind.INDEX, 2); | 71 const Selector(SelectorKind.INDEX, 2); |
| 72 static final Selector GETTER_AND_SETTER = | 72 static final Selector GETTER_AND_SETTER = |
| 73 const Selector(SelectorKind.SETTER, 1); | 73 const Selector(SelectorKind.SETTER, 1); |
| 74 static final Selector INVOCATION_0 = | 74 static final Selector INVOCATION_0 = |
| 75 const Selector(SelectorKind.INVOCATION, 0); | 75 const Selector(SelectorKind.INVOCATION, 0); |
| 76 static final Selector INVOCATION_1 = | 76 static final Selector INVOCATION_1 = |
| 77 const Selector(SelectorKind.INVOCATION, 1); | 77 const Selector(SelectorKind.INVOCATION, 1); |
| 78 static final Selector INVOCATION_2 = | 78 static final Selector INVOCATION_2 = |
| 79 const Selector(SelectorKind.INVOCATION, 2); | 79 const Selector(SelectorKind.INVOCATION, 2); |
| 80 | 80 |
| 81 bool applies(FunctionParameters parameters) { | 81 bool applies(FunctionElement element, Compiler compiler) { |
| 82 FunctionParameters parameters = element.computeParameters(compiler); |
| 82 if (argumentCount > parameters.parameterCount) return false; | 83 if (argumentCount > parameters.parameterCount) return false; |
| 83 int requiredParameterCount = parameters.requiredParameterCount; | 84 int requiredParameterCount = parameters.requiredParameterCount; |
| 84 int optionalParameterCount = parameters.optionalParameterCount; | 85 int optionalParameterCount = parameters.optionalParameterCount; |
| 85 if (positionalArgumentCount < requiredParameterCount) return false; | 86 if (positionalArgumentCount < requiredParameterCount) return false; |
| 86 | 87 |
| 87 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); | 88 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); |
| 88 if (namedArguments.isEmpty()) { | 89 if (namedArguments.isEmpty()) { |
| 89 if (!hasOptionalParameters) { | 90 if (!hasOptionalParameters) { |
| 90 return requiredParameterCount == argumentCount; | 91 return requiredParameterCount == argumentCount; |
| 91 } else { | 92 } else { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 114 return true; | 115 return true; |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 | 118 |
| 118 /** | 119 /** |
| 119 * Returns [:true:] if the selector and the [element] match; [:false:] | 120 * Returns [:true:] if the selector and the [element] match; [:false:] |
| 120 * otherwise. | 121 * otherwise. |
| 121 */ | 122 */ |
| 122 bool addArgumentsToList(Link<Node> arguments, | 123 bool addArgumentsToList(Link<Node> arguments, |
| 123 List list, | 124 List list, |
| 124 FunctionParameters parameters, | 125 FunctionElement element, |
| 125 compileArgument(Node argument), | 126 compileArgument(Node argument), |
| 126 compileConstant(Element element)) { | 127 compileConstant(Element element), |
| 127 void addMatchingArgumentsToList(Link<Node> link) { | 128 Compiler compiler) { |
| 128 } | 129 if (!this.applies(element, compiler)) return false; |
| 129 | 130 |
| 130 if (!this.applies(parameters)) return false; | 131 void addMatchingArgumentsToList(Link<Node> link) {} |
| 132 |
| 133 FunctionParameters parameters = element.computeParameters(compiler); |
| 131 if (this.positionalArgumentCount == parameters.parameterCount) { | 134 if (this.positionalArgumentCount == parameters.parameterCount) { |
| 132 for (Link<Node> link = arguments; !link.isEmpty(); link = link.tail) { | 135 for (Link<Node> link = arguments; !link.isEmpty(); link = link.tail) { |
| 133 list.add(compileArgument(link.head)); | 136 list.add(compileArgument(link.head)); |
| 134 } | 137 } |
| 135 return true; | 138 return true; |
| 136 } | 139 } |
| 137 | 140 |
| 138 // If there are named arguments, provide them in the order | 141 // If there are named arguments, provide them in the order |
| 139 // expected by the called function, which is the source order. | 142 // expected by the called function, which is the source order. |
| 140 | 143 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments; | 226 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments; |
| 224 | 227 |
| 225 List<SourceString> list = new List<SourceString>.from(namedArguments); | 228 List<SourceString> list = new List<SourceString>.from(namedArguments); |
| 226 list.sort((SourceString first, SourceString second) { | 229 list.sort((SourceString first, SourceString second) { |
| 227 return first.slowToString().compareTo(second.slowToString()); | 230 return first.slowToString().compareTo(second.slowToString()); |
| 228 }); | 231 }); |
| 229 orderedNamedArguments = list; | 232 orderedNamedArguments = list; |
| 230 return orderedNamedArguments; | 233 return orderedNamedArguments; |
| 231 } | 234 } |
| 232 } | 235 } |
| 236 |
| 237 /** |
| 238 * A [TypedInvocation] is an invocation where we have information on |
| 239 * the type of the receiver. |
| 240 */ |
| 241 class TypedInvocation extends Invocation { |
| 242 /** |
| 243 * The type of the receiver. Any subtype of that type can be the |
| 244 * target of the invocation. |
| 245 */ |
| 246 final Type receiverType; |
| 247 |
| 248 TypedInvocation(this.receiverType, Selector selector) |
| 249 : super(selector.argumentCount, selector.namedArguments); |
| 250 |
| 251 bool applies(FunctionElement element, Compiler compiler) { |
| 252 if (!element.enclosingElement.isClass()) return false; |
| 253 |
| 254 ClassElement other = element.enclosingElement; |
| 255 ClassElement self = receiverType.element; |
| 256 if (!other.isSubclassOf(self)) return false; |
| 257 return super.applies(element, compiler); |
| 258 return false; |
| 259 } |
| 260 |
| 261 bool operator ==(other) { |
| 262 if (other is !TypedInvocation) return false; |
| 263 if (other.receiverType !== receiverType) return false; |
| 264 return super == other; |
| 265 } |
| 266 } |
| OLD | NEW |