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 types; | 5 library types; |
6 | 6 |
7 import '../dart2jslib.dart' hide Selector; | 7 import '../dart2jslib.dart' hide Selector; |
8 import '../tree/tree.dart'; | 8 import '../tree/tree.dart'; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../util/util.dart'; | 10 import '../util/util.dart'; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 if (guaranteedType != null) return guaranteedType; | 61 if (guaranteedType != null) return guaranteedType; |
62 } | 62 } |
63 Element holder = element.enclosingElement; | 63 Element holder = element.enclosingElement; |
64 Link<Element> types = typedSends[holder]; | 64 Link<Element> types = typedSends[holder]; |
65 if (types == null) return null; | 65 if (types == null) return null; |
66 if (!holder.isFunction()) return null; | 66 if (!holder.isFunction()) return null; |
67 if (untypedElements.contains(holder)) return null; | 67 if (untypedElements.contains(holder)) return null; |
68 FunctionElement function = holder; | 68 FunctionElement function = holder; |
69 FunctionSignature signature = function.computeSignature(compiler); | 69 FunctionSignature signature = function.computeSignature(compiler); |
70 for (Element parameter in signature.requiredParameters) { | 70 for (Element parameter in signature.requiredParameters) { |
71 if (types.isEmpty()) return null; | 71 if (types.isEmpty) return null; |
72 if (element == parameter) { | 72 if (element == parameter) { |
73 return new ConcreteType.singleton(new ClassBaseType(types.head)); | 73 return new ConcreteType.singleton(new ClassBaseType(types.head)); |
74 } | 74 } |
75 types = types.tail; | 75 types = types.tail; |
76 } | 76 } |
77 return null; | 77 return null; |
78 }); | 78 }); |
79 } | 79 } |
80 | 80 |
81 /** | 81 /** |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 node.visitChildren(this); | 158 node.visitChildren(this); |
159 // TODO(ahe): map class? | 159 // TODO(ahe): map class? |
160 } | 160 } |
161 | 161 |
162 visitLiteralNull(LiteralNull node) { | 162 visitLiteralNull(LiteralNull node) { |
163 recordConcreteType(node, nullClass); | 163 recordConcreteType(node, nullClass); |
164 } | 164 } |
165 | 165 |
166 Link<Element> computeConcreteSendArguments(Send node) { | 166 Link<Element> computeConcreteSendArguments(Send node) { |
167 if (node.argumentsNode == null) return null; | 167 if (node.argumentsNode == null) return null; |
168 if (node.arguments.isEmpty()) return const Link<Element>(); | 168 if (node.arguments.isEmpty) return const Link<Element>(); |
169 if (node.receiver != null && concreteTypes[node.receiver] == null) { | 169 if (node.receiver != null && concreteTypes[node.receiver] == null) { |
170 return null; | 170 return null; |
171 } | 171 } |
172 LinkBuilder<Element> types = new LinkBuilder<Element>(); | 172 LinkBuilder<Element> types = new LinkBuilder<Element>(); |
173 for (Node argument in node.arguments) { | 173 for (Node argument in node.arguments) { |
174 Element type = concreteTypes[argument]; | 174 Element type = concreteTypes[argument]; |
175 if (type == null) return null; | 175 if (type == null) return null; |
176 types.addLast(type); | 176 types.addLast(type); |
177 } | 177 } |
178 return types.toLink(); | 178 return types.toLink(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 task.compiler.reportWarning(node, message); | 219 task.compiler.reportWarning(node, message); |
220 } | 220 } |
221 | 221 |
222 /** | 222 /** |
223 * Computes the pairwise Least Upper Bound (LUB) of the elements of | 223 * Computes the pairwise Least Upper Bound (LUB) of the elements of |
224 * [a] and [b]. Returns [:null:] if it gives up, or if the lists | 224 * [a] and [b]. Returns [:null:] if it gives up, or if the lists |
225 * aren't the same length. | 225 * aren't the same length. |
226 */ | 226 */ |
227 Link<Element> computeLubs(Link<Element> a, Link<Element> b) { | 227 Link<Element> computeLubs(Link<Element> a, Link<Element> b) { |
228 LinkBuilder<Element> lubs = new LinkBuilder<Element>(); | 228 LinkBuilder<Element> lubs = new LinkBuilder<Element>(); |
229 while (!a.isEmpty() && !b.isEmpty()) { | 229 while (!a.isEmpty && !b.isEmpty) { |
230 Element lub = computeLub(a.head, b.head); | 230 Element lub = computeLub(a.head, b.head); |
231 if (lub == null) return null; | 231 if (lub == null) return null; |
232 lubs.addLast(lub); | 232 lubs.addLast(lub); |
233 a = a.tail; | 233 a = a.tail; |
234 b = b.tail; | 234 b = b.tail; |
235 } | 235 } |
236 return (a.isEmpty() && b.isEmpty()) ? lubs.toLink() : null; | 236 return (a.isEmpty && b.isEmpty) ? lubs.toLink() : null; |
237 } | 237 } |
238 | 238 |
239 /** | 239 /** |
240 * Computes the Least Upper Bound (LUB) of [a] and [b]. Returns | 240 * Computes the Least Upper Bound (LUB) of [a] and [b]. Returns |
241 * [:null:] if it gives up. | 241 * [:null:] if it gives up. |
242 */ | 242 */ |
243 Element computeLub(Element a, Element b) { | 243 Element computeLub(Element a, Element b) { |
244 // Fast common case, but also simple initial implementation. | 244 // Fast common case, but also simple initial implementation. |
245 if (identical(a, b)) return a; | 245 if (identical(a, b)) return a; |
246 | 246 |
247 // TODO(ahe): Improve the following "computation"... | 247 // TODO(ahe): Improve the following "computation"... |
248 return null; | 248 return null; |
249 } | 249 } |
250 } | 250 } |
OLD | NEW |