| 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 interface TreeElements { | 5 interface TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 Type getType(TypeAnnotation annotation); | 8 Type getType(TypeAnnotation annotation); |
| 9 } | 9 } |
| 10 | 10 |
| 11 class TreeElementMapping implements TreeElements { | 11 class TreeElementMapping implements TreeElements { |
| 12 Map<Node, Element> map; | 12 Map<Node, Element> map; |
| 13 Map<Send, Selector> selectors; | 13 Map<Node, Selector> selectors; |
| 14 Map<TypeAnnotation, Type> types; | 14 Map<TypeAnnotation, Type> types; |
| 15 | 15 |
| 16 TreeElementMapping() | 16 TreeElementMapping() |
| 17 : map = new LinkedHashMap<Node, Element>(), | 17 : map = new LinkedHashMap<Node, Element>(), |
| 18 selectors = new LinkedHashMap<Send, Selector>(), | 18 selectors = new LinkedHashMap<Node, Selector>(), |
| 19 types = new LinkedHashMap<TypeAnnotation, Type>(); | 19 types = new LinkedHashMap<TypeAnnotation, Type>(); |
| 20 | 20 |
| 21 operator []=(Node node, Element element) => map[node] = element; | 21 operator []=(Node node, Element element) => map[node] = element; |
| 22 operator [](Node node) => map[node]; | 22 operator [](Node node) => map[node]; |
| 23 void remove(Node node) { map.remove(node); } | 23 void remove(Node node) { map.remove(node); } |
| 24 | 24 |
| 25 void setType(TypeAnnotation annotation, Type type) { | 25 void setType(TypeAnnotation annotation, Type type) { |
| 26 types[annotation] = type; | 26 types[annotation] = type; |
| 27 } | 27 } |
| 28 | 28 |
| 29 Type getType(TypeAnnotation annotation) => types[annotation]; | 29 Type getType(TypeAnnotation annotation) => types[annotation]; |
| 30 | 30 |
| 31 void setSelector(Send send, Selector selector) { | 31 void setSelector(Node node, Selector selector) { |
| 32 selectors[send] = selector; | 32 selectors[node] = selector; |
| 33 } | 33 } |
| 34 | 34 |
| 35 Selector getSelector(Send send) => selectors[send]; | 35 Selector getSelector(Node node) => selectors[node]; |
| 36 } | 36 } |
| 37 | 37 |
| 38 class ResolverTask extends CompilerTask { | 38 class ResolverTask extends CompilerTask { |
| 39 ResolverTask(Compiler compiler) : super(compiler); | 39 ResolverTask(Compiler compiler) : super(compiler); |
| 40 | 40 |
| 41 String get name() => 'Resolver'; | 41 String get name() => 'Resolver'; |
| 42 | 42 |
| 43 TreeElements resolve(Element element) { | 43 TreeElements resolve(Element element) { |
| 44 return measure(() { | 44 return measure(() { |
| 45 ElementKind kind = element.kind; | 45 ElementKind kind = element.kind; |
| (...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 | 1332 |
| 1333 // TODO(ngeoffray): Check if the target can be assigned. | 1333 // TODO(ngeoffray): Check if the target can be assigned. |
| 1334 // TODO(ngeoffray): Warn if target is null and the send is | 1334 // TODO(ngeoffray): Warn if target is null and the send is |
| 1335 // unqualified. | 1335 // unqualified. |
| 1336 | 1336 |
| 1337 Selector selector = mapping.getSelector(node); | 1337 Selector selector = mapping.getSelector(node); |
| 1338 String source = node.assignmentOperator.source.stringValue; | 1338 String source = node.assignmentOperator.source.stringValue; |
| 1339 bool isComplex = source !== '='; | 1339 bool isComplex = source !== '='; |
| 1340 if (isComplex) { | 1340 if (isComplex) { |
| 1341 if (selector.isSetter()) { | 1341 if (selector.isSetter()) { |
| 1342 // TODO(kasperl): We're registering the getter selector for |
| 1343 // compound assignments on the AST selector node. In the code |
| 1344 // generator, we then fetch it from there when generating the |
| 1345 // getter for a SendSet node. |
| 1346 Selector getterSelector = new Selector.getterFrom(selector); |
| 1347 registerSend(getterSelector, getter); |
| 1348 mapping.setSelector(node.selector, getterSelector); |
| 1342 useElement(node.selector, getter); | 1349 useElement(node.selector, getter); |
| 1343 registerSend(new Selector.getterFrom(selector), getter); | |
| 1344 } else { | 1350 } else { |
| 1345 // TODO(kasperl): If [getter] is resolved, it will actually | 1351 // TODO(kasperl): If [getter] is resolved, it will actually |
| 1346 // refer to the []= operator which isn't the one we want to | 1352 // refer to the []= operator which isn't the one we want to |
| 1347 // register here. We should consider using some notion of | 1353 // register here. We should consider using some notion of |
| 1348 // abstract indexable element that we can resolve to so we can | 1354 // abstract indexable element that we can resolve to so we can |
| 1349 // distinguish the two. | 1355 // distinguish the two. |
| 1350 assert(selector.isIndexSet()); | 1356 assert(selector.isIndexSet()); |
| 1351 registerSend(new Selector.index(), null); | 1357 registerSend(new Selector.index(), null); |
| 1352 } | 1358 } |
| 1353 | 1359 |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2508 TopScope(LibraryElement library) : super(null, library); | 2514 TopScope(LibraryElement library) : super(null, library); |
| 2509 Element lookup(SourceString name) { | 2515 Element lookup(SourceString name) { |
| 2510 return library.find(name); | 2516 return library.find(name); |
| 2511 } | 2517 } |
| 2512 | 2518 |
| 2513 Element add(Element newElement) { | 2519 Element add(Element newElement) { |
| 2514 throw "Cannot add an element in the top scope"; | 2520 throw "Cannot add an element in the top scope"; |
| 2515 } | 2521 } |
| 2516 String toString() => '$element'; | 2522 String toString() => '$element'; |
| 2517 } | 2523 } |
| OLD | NEW |