| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Returns [:true:] if the selector and the [element] match; [:false:] | 117 * Returns [:true:] if the selector and the [element] match; [:false:] |
| 118 * otherwise. | 118 * otherwise. |
| 119 */ | 119 */ |
| 120 bool addSendArgumentsToList(Send send, | 120 bool addSendArgumentsToList(Send send, |
| 121 List list, | 121 List list, |
| 122 FunctionParameters parameters, | 122 FunctionParameters parameters, |
| 123 visitArgument(Node argument), | 123 compileArgument(Node argument), |
| 124 visitConstant(Element element)) { | 124 compileConstant(Element element)) { |
| 125 void addMatchingSendArgumentsToList(Link<Node> link) { | 125 void addMatchingSendArgumentsToList(Link<Node> link) { |
| 126 for (; !link.isEmpty(); link = link.tail) { | 126 for (; !link.isEmpty(); link = link.tail) { |
| 127 list.add(visitArgument(link.head)); | 127 list.add(compileArgument(link.head)); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (!this.applies(parameters)) return false; | 131 if (!this.applies(parameters)) return false; |
| 132 if (this.positionalArgumentCount == parameters.parameterCount) { | 132 if (this.positionalArgumentCount == parameters.parameterCount) { |
| 133 addMatchingSendArgumentsToList(send.arguments); | 133 addMatchingSendArgumentsToList(send.arguments); |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // If there are named arguments, provide them in the order | 137 // If there are named arguments, provide them in the order |
| 138 // expected by the called function, which is the source order. | 138 // expected by the called function, which is the source order. |
| 139 | 139 |
| 140 // Visit positional arguments and add them to the list. | 140 // Visit positional arguments and add them to the list. |
| 141 Link<Node> arguments = send.arguments; | 141 Link<Node> arguments = send.arguments; |
| 142 int positionalArgumentCount = this.positionalArgumentCount; | 142 int positionalArgumentCount = this.positionalArgumentCount; |
| 143 for (int i = 0; | 143 for (int i = 0; |
| 144 i < positionalArgumentCount; | 144 i < positionalArgumentCount; |
| 145 arguments = arguments.tail, i++) { | 145 arguments = arguments.tail, i++) { |
| 146 list.add(visitArgument(arguments.head)); | 146 list.add(compileArgument(arguments.head)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Visit named arguments and add them into a temporary list. | 149 // Visit named arguments and add them into a temporary list. |
| 150 List namedArguments = []; | 150 List namedArguments = []; |
| 151 for (; !arguments.isEmpty(); arguments = arguments.tail) { | 151 for (; !arguments.isEmpty(); arguments = arguments.tail) { |
| 152 namedArguments.add(visitArgument(arguments.head)); | 152 NamedArgument namedArgument = arguments.head; |
| 153 namedArguments.add(compileArgument(namedArgument.expression)); |
| 153 } | 154 } |
| 154 | 155 |
| 155 Link<Element> remainingNamedParameters = parameters.optionalParameters; | 156 Link<Element> remainingNamedParameters = parameters.optionalParameters; |
| 156 // Skip the optional parameters that have been given in the | 157 // Skip the optional parameters that have been given in the |
| 157 // positional arguments. | 158 // positional arguments. |
| 158 for (int i = parameters.requiredParameterCount; | 159 for (int i = parameters.requiredParameterCount; |
| 159 i < positionalArgumentCount; | 160 i < positionalArgumentCount; |
| 160 i++) { | 161 i++) { |
| 161 remainingNamedParameters = remainingNamedParameters.tail; | 162 remainingNamedParameters = remainingNamedParameters.tail; |
| 162 } | 163 } |
| 163 | 164 |
| 164 // Loop over the remaining named parameters, and try to find | 165 // Loop over the remaining named parameters, and try to find |
| 165 // their values: either in the temporary list or using the | 166 // their values: either in the temporary list or using the |
| 166 // default value. | 167 // default value. |
| 167 for (; | 168 for (; |
| 168 !remainingNamedParameters.isEmpty(); | 169 !remainingNamedParameters.isEmpty(); |
| 169 remainingNamedParameters = remainingNamedParameters.tail) { | 170 remainingNamedParameters = remainingNamedParameters.tail) { |
| 170 Element parameter = remainingNamedParameters.head; | 171 Element parameter = remainingNamedParameters.head; |
| 171 int foundIndex = -1; | 172 int foundIndex = -1; |
| 172 for (int i = 0; i < this.namedArguments.length; i++) { | 173 for (int i = 0; i < this.namedArguments.length; i++) { |
| 173 SourceString name = this.namedArguments[i]; | 174 SourceString name = this.namedArguments[i]; |
| 174 if (name == parameter.name) { | 175 if (name == parameter.name) { |
| 175 foundIndex = i; | 176 foundIndex = i; |
| 176 break; | 177 break; |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 if (foundIndex != -1) { | 180 if (foundIndex != -1) { |
| 180 list.add(namedArguments[foundIndex]); | 181 list.add(namedArguments[foundIndex]); |
| 181 } else { | 182 } else { |
| 182 list.add(visitConstant(parameter)); | 183 list.add(compileConstant(parameter)); |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 return true; | 186 return true; |
| 186 } | 187 } |
| 187 | 188 |
| 188 static bool sameNames(List<SourceString> first, List<SourceString> second) { | 189 static bool sameNames(List<SourceString> first, List<SourceString> second) { |
| 189 for (int i = 0; i < first.length; i++) { | 190 for (int i = 0; i < first.length; i++) { |
| 190 if (first[i] != second[i]) return false; | 191 if (first[i] != second[i]) return false; |
| 191 } | 192 } |
| 192 return true; | 193 return true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 222 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments; | 223 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments; |
| 223 | 224 |
| 224 List<SourceString> list = new List<SourceString>.from(namedArguments); | 225 List<SourceString> list = new List<SourceString>.from(namedArguments); |
| 225 list.sort((SourceString first, SourceString second) { | 226 list.sort((SourceString first, SourceString second) { |
| 226 return first.slowToString().compareTo(second.slowToString()); | 227 return first.slowToString().compareTo(second.slowToString()); |
| 227 }); | 228 }); |
| 228 orderedNamedArguments = list; | 229 orderedNamedArguments = list; |
| 229 return orderedNamedArguments; | 230 return orderedNamedArguments; |
| 230 } | 231 } |
| 231 } | 232 } |
| OLD | NEW |