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 DartType getType(TypeAnnotation annotation); | 8 DartType getType(TypeAnnotation annotation); |
9 bool isParameterChecked(Element element); | |
9 } | 10 } |
10 | 11 |
11 class TreeElementMapping implements TreeElements { | 12 class TreeElementMapping implements TreeElements { |
12 Map<Node, Element> map; | 13 final Map<Node, Element> map; |
13 Map<Node, Selector> selectors; | 14 final Map<Node, Selector> selectors; |
14 Map<TypeAnnotation, DartType> types; | 15 final Map<TypeAnnotation, DartType> types; |
16 final Set<Element> checkedParameters; | |
kasperl
2012/09/04 10:50:08
Thanks for trying to come up with a better name. C
| |
15 | 17 |
16 TreeElementMapping() | 18 TreeElementMapping() |
17 : map = new LinkedHashMap<Node, Element>(), | 19 : map = new LinkedHashMap<Node, Element>(), |
18 selectors = new LinkedHashMap<Node, Selector>(), | 20 selectors = new LinkedHashMap<Node, Selector>(), |
19 types = new LinkedHashMap<TypeAnnotation, DartType>(); | 21 types = new LinkedHashMap<TypeAnnotation, DartType>(), |
22 checkedParameters = new Set<Element>(); | |
20 | 23 |
21 operator []=(Node node, Element element) => map[node] = element; | 24 operator []=(Node node, Element element) => map[node] = element; |
22 operator [](Node node) => map[node]; | 25 operator [](Node node) => map[node]; |
23 void remove(Node node) { map.remove(node); } | 26 void remove(Node node) { map.remove(node); } |
24 | 27 |
25 void setType(TypeAnnotation annotation, DartType type) { | 28 void setType(TypeAnnotation annotation, DartType type) { |
26 types[annotation] = type; | 29 types[annotation] = type; |
27 } | 30 } |
28 | 31 |
29 DartType getType(TypeAnnotation annotation) => types[annotation]; | 32 DartType getType(TypeAnnotation annotation) => types[annotation]; |
30 | 33 |
31 void setSelector(Node node, Selector selector) { | 34 void setSelector(Node node, Selector selector) { |
32 selectors[node] = selector; | 35 selectors[node] = selector; |
33 } | 36 } |
34 | 37 |
35 Selector getSelector(Node node) => selectors[node]; | 38 Selector getSelector(Node node) => selectors[node]; |
39 | |
40 bool isParameterChecked(Element element) { | |
41 return checkedParameters.contains(element); | |
42 } | |
36 } | 43 } |
37 | 44 |
38 class ResolverTask extends CompilerTask { | 45 class ResolverTask extends CompilerTask { |
39 ResolverTask(Compiler compiler) : super(compiler); | 46 ResolverTask(Compiler compiler) : super(compiler); |
40 | 47 |
41 String get name => 'Resolver'; | 48 String get name => 'Resolver'; |
42 | 49 |
43 TreeElements resolve(Element element) { | 50 TreeElements resolve(Element element) { |
44 return measure(() { | 51 return measure(() { |
45 ElementKind kind = element.kind; | 52 ElementKind kind = element.kind; |
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 String operatorString = node.selector.asOperator().source.stringValue; | 1347 String operatorString = node.selector.asOperator().source.stringValue; |
1341 if (operatorString === 'is' || operatorString === 'as') { | 1348 if (operatorString === 'is' || operatorString === 'as') { |
1342 assert(node.arguments.tail.isEmpty()); | 1349 assert(node.arguments.tail.isEmpty()); |
1343 resolveTypeTest(node.arguments.head); | 1350 resolveTypeTest(node.arguments.head); |
1344 resolvedArguments = true; | 1351 resolvedArguments = true; |
1345 } else if (operatorString === '?') { | 1352 } else if (operatorString === '?') { |
1346 Element parameter = mapping[node.receiver]; | 1353 Element parameter = mapping[node.receiver]; |
1347 if (parameter === null || parameter.kind !== ElementKind.PARAMETER) { | 1354 if (parameter === null || parameter.kind !== ElementKind.PARAMETER) { |
1348 error(node.receiver, MessageKind.PARAMETER_NAME_EXPECTED); | 1355 error(node.receiver, MessageKind.PARAMETER_NAME_EXPECTED); |
1349 } else { | 1356 } else { |
1350 warning(node, MessageKind.GENERIC, | 1357 mapping.checkedParameters.add(parameter); |
1351 ['argument definition test operator is not implemented.']); | |
1352 } | 1358 } |
1353 } | 1359 } |
1354 } | 1360 } |
1355 | 1361 |
1356 if (!resolvedArguments) { | 1362 if (!resolvedArguments) { |
1357 resolveArguments(node.argumentsNode); | 1363 resolveArguments(node.argumentsNode); |
1358 } | 1364 } |
1359 | 1365 |
1360 // If the selector is null, it means that we will not be generating | 1366 // If the selector is null, it means that we will not be generating |
1361 // code for this as a send. | 1367 // code for this as a send. |
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2636 TopScope(LibraryElement library) : super(null, library); | 2642 TopScope(LibraryElement library) : super(null, library); |
2637 Element lookup(SourceString name) { | 2643 Element lookup(SourceString name) { |
2638 return library.find(name); | 2644 return library.find(name); |
2639 } | 2645 } |
2640 | 2646 |
2641 Element add(Element newElement) { | 2647 Element add(Element newElement) { |
2642 throw "Cannot add an element in the top scope"; | 2648 throw "Cannot add an element in the top scope"; |
2643 } | 2649 } |
2644 String toString() => '$element'; | 2650 String toString() => '$element'; |
2645 } | 2651 } |
OLD | NEW |