| 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 } | 8 } |
| 9 | 9 |
| 10 class TreeElementMapping implements TreeElements { | 10 class TreeElementMapping implements TreeElements { |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 visit(node.condition); | 793 visit(node.condition); |
| 794 visitLoopBodyIn(node, node.body, new BlockScope(context)); | 794 visitLoopBodyIn(node, node.body, new BlockScope(context)); |
| 795 } | 795 } |
| 796 | 796 |
| 797 visitParenthesizedExpression(ParenthesizedExpression node) { | 797 visitParenthesizedExpression(ParenthesizedExpression node) { |
| 798 visit(node.expression); | 798 visit(node.expression); |
| 799 } | 799 } |
| 800 | 800 |
| 801 visitNewExpression(NewExpression node) { | 801 visitNewExpression(NewExpression node) { |
| 802 if (node.isConst()) cancel(node, 'const expressions are not implemented'); | 802 if (node.isConst()) cancel(node, 'const expressions are not implemented'); |
| 803 if (node.send.selector.asTypeAnnotation() === null) { | 803 Node selector = node.send.selector; |
| 804 if (selector.asTypeAnnotation() === null) { |
| 804 cancel( | 805 cancel( |
| 805 node, 'named constructors with type arguments are not implemented'); | 806 node, 'named constructors with type arguments are not implemented'); |
| 806 } | 807 } |
| 807 | 808 |
| 808 SourceString constructorName; | 809 SourceString constructorName; |
| 809 Node typeName = node.send.selector.asTypeAnnotation().typeName; | 810 Node typeName = selector.asTypeAnnotation().typeName; |
| 810 if (typeName.asSend() !== null) { | 811 if (typeName.asSend() !== null) { |
| 811 Identifier receiver = typeName.asSend().receiver.asIdentifier(); | 812 Identifier receiver = typeName.asSend().receiver.asIdentifier(); |
| 812 Identifier selector = typeName.asSend().selector.asIdentifier(); | 813 Identifier selector = typeName.asSend().selector.asIdentifier(); |
| 813 SourceString className = receiver.source; | 814 SourceString className = receiver.source; |
| 814 SourceString name = selector.source; | 815 SourceString name = selector.source; |
| 815 constructorName = Elements.constructConstructorName(className, name); | 816 constructorName = Elements.constructConstructorName(className, name); |
| 816 } else { | 817 } else { |
| 817 constructorName = typeName.asIdentifier().source; | 818 constructorName = typeName.asIdentifier().source; |
| 818 } | 819 } |
| 819 ClassElement cls = resolveTypeRequired(node.send.selector); | 820 ClassElement cls = resolveTypeRequired(selector); |
| 820 Element constructor = null; | 821 Element constructor = null; |
| 821 if (cls !== null) { | 822 if (cls !== null) { |
| 822 constructor = cls.resolve(compiler).lookupConstructor(constructorName); | 823 cls.resolve(compiler); |
| 824 if (cls.isInterface() && (cls.defaultClass === null)) { |
| 825 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); |
| 826 } |
| 827 constructor = cls.lookupConstructor(constructorName); |
| 823 if (constructorName == cls.name | 828 if (constructorName == cls.name |
| 824 && constructor === null | 829 && constructor === null |
| 825 && node.send.argumentsNode.isEmpty()) { | 830 && node.send.argumentsNode.isEmpty()) { |
| 826 constructor = cls.getSynthesizedConstructor(); | 831 constructor = cls.getSynthesizedConstructor(); |
| 827 } | 832 } |
| 828 if (constructor === null) { | 833 if (constructor === null) { |
| 829 error(node.send, MessageKind.CANNOT_FIND_CONSTRUCTOR, [node.send]); | 834 error(node.send, MessageKind.CANNOT_FIND_CONSTRUCTOR, [node.send]); |
| 830 } else { | 835 } else { |
| 831 FunctionElement function = constructor; | 836 FunctionElement function = constructor; |
| 832 // TODO(karlklose): handle optional arguments. | 837 // TODO(karlklose): handle optional arguments. |
| 833 if (node.send.argumentCount() != function.parameterCount(compiler)) { | 838 if (node.send.argumentCount() != function.parameterCount(compiler)) { |
| 834 // TODO(ngeoffray): reslution error with wrong number of | 839 // TODO(ngeoffray): reslution error with wrong number of |
| 835 // parameters. We cannot do this rigth now because of the | 840 // parameters. We cannot do this rigth now because of the |
| 836 // List constructor. | 841 // List constructor. |
| 837 } | 842 } |
| 838 } | 843 } |
| 839 } else { | 844 } else { |
| 840 Node selector = node.send.selector; | |
| 841 error(selector, MessageKind.CANNOT_RESOLVE_TYPE, [selector]); | 845 error(selector, MessageKind.CANNOT_RESOLVE_TYPE, [selector]); |
| 842 } | 846 } |
| 843 handleArguments(node.send); | 847 handleArguments(node.send); |
| 844 useElement(node.send, constructor); | 848 useElement(node.send, constructor); |
| 845 return null; | 849 return null; |
| 846 } | 850 } |
| 847 | 851 |
| 848 ClassElement resolveTypeRequired(Node node) { | 852 ClassElement resolveTypeRequired(Node node) { |
| 849 bool old = typeRequired; | 853 bool old = typeRequired; |
| 850 typeRequired = true; | 854 typeRequired = true; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 if (element.name != Types.OBJECT && element.supertype === null) { | 1021 if (element.name != Types.OBJECT && element.supertype === null) { |
| 1018 ClassElement objectElement = context.lookup(Types.OBJECT); | 1022 ClassElement objectElement = context.lookup(Types.OBJECT); |
| 1019 if (objectElement !== null && !objectElement.isResolved) { | 1023 if (objectElement !== null && !objectElement.isResolved) { |
| 1020 compiler.resolver.toResolve.add(objectElement); | 1024 compiler.resolver.toResolve.add(objectElement); |
| 1021 } else if (objectElement === null){ | 1025 } else if (objectElement === null){ |
| 1022 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [Types.OBJECT]); | 1026 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [Types.OBJECT]); |
| 1023 } | 1027 } |
| 1024 element.supertype = new SimpleType(Types.OBJECT, | 1028 element.supertype = new SimpleType(Types.OBJECT, |
| 1025 objectElement); | 1029 objectElement); |
| 1026 } | 1030 } |
| 1031 if (node.defaultClause !== null) { |
| 1032 element.defaultClass = visit(node.defaultClause.nodes.head); |
| 1033 } |
| 1027 for (Link<Node> link = node.interfaces.nodes; | 1034 for (Link<Node> link = node.interfaces.nodes; |
| 1028 !link.isEmpty(); | 1035 !link.isEmpty(); |
| 1029 link = link.tail) { | 1036 link = link.tail) { |
| 1030 element.interfaces = element.interfaces.prepend(visit(link.head)); | 1037 element.interfaces = element.interfaces.prepend(visit(link.head)); |
| 1031 } | 1038 } |
| 1032 return element.computeType(compiler); | 1039 return element.computeType(compiler); |
| 1033 } | 1040 } |
| 1034 | 1041 |
| 1035 Type visitTypeAnnotation(TypeAnnotation node) { | 1042 Type visitTypeAnnotation(TypeAnnotation node) { |
| 1036 Identifier name = node.typeName.asIdentifier(); | 1043 Identifier name = node.typeName.asIdentifier(); |
| 1037 if (name === null) { | 1044 if (name === null) { |
| 1038 unimplemented(node.typeName, "prefixes"); | 1045 unimplemented(node.typeName, "prefixes"); |
| 1039 } | 1046 } |
| 1040 Element element = context.lookup(name.source); | 1047 return visit(name); |
| 1048 } |
| 1049 |
| 1050 Type visitIdentifier(Identifier node) { |
| 1051 Element element = context.lookup(node.source); |
| 1041 if (element === null) { | 1052 if (element === null) { |
| 1042 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [name]); | 1053 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [node]); |
| 1043 } else if (element.kind !== ElementKind.CLASS) { | 1054 } else if (element.kind !== ElementKind.CLASS) { |
| 1044 error(node, MessageKind.NOT_A_TYPE, [name]); | 1055 error(node, MessageKind.NOT_A_TYPE, [node]); |
| 1045 } else { | 1056 } else { |
| 1046 compiler.resolver.toResolve.add(element); | 1057 compiler.resolver.toResolve.add(element); |
| 1047 // TODO(ngeoffray): Use type variables. | 1058 // TODO(ngeoffray): Use type variables. |
| 1048 return element.computeType(compiler); | 1059 return element.computeType(compiler); |
| 1049 } | 1060 } |
| 1050 return null; | 1061 return null; |
| 1051 } | 1062 } |
| 1052 } | 1063 } |
| 1053 | 1064 |
| 1054 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { | 1065 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 class TopScope extends Scope { | 1292 class TopScope extends Scope { |
| 1282 LibraryElement get library() => element; | 1293 LibraryElement get library() => element; |
| 1283 | 1294 |
| 1284 TopScope(LibraryElement library) : super(null, library); | 1295 TopScope(LibraryElement library) : super(null, library); |
| 1285 Element lookup(SourceString name) => library.find(name); | 1296 Element lookup(SourceString name) => library.find(name); |
| 1286 | 1297 |
| 1287 Element add(Element element) { | 1298 Element add(Element element) { |
| 1288 throw "Cannot add an element in the top scope"; | 1299 throw "Cannot add an element in the top scope"; |
| 1289 } | 1300 } |
| 1290 } | 1301 } |
| OLD | NEW |