| 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 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 TreeElements resolveParameter(Element element) { | 206 TreeElements resolveParameter(Element element) { |
| 207 Node tree = element.parseNode(compiler); | 207 Node tree = element.parseNode(compiler); |
| 208 ResolverVisitor visitor = | 208 ResolverVisitor visitor = |
| 209 new ResolverVisitor(compiler, element.enclosingElement); | 209 new ResolverVisitor(compiler, element.enclosingElement); |
| 210 initializerDo(tree, visitor.visit); | 210 initializerDo(tree, visitor.visit); |
| 211 return visitor.mapping; | 211 return visitor.mapping; |
| 212 } | 212 } |
| 213 | 213 |
| 214 Type resolveType(ClassElement element) { | 214 void resolveClass(ClassElement element) { |
| 215 if (element.isResolved) return element.type; | 215 if (element.isResolved) return; |
| 216 return measure(() { | 216 measure(() { |
| 217 ClassNode tree = element.parseNode(compiler); | 217 ClassNode tree = element.parseNode(compiler); |
| 218 ClassResolverVisitor visitor = | 218 ClassResolverVisitor visitor = |
| 219 new ClassResolverVisitor(compiler, element.getLibrary(), element); | 219 new ClassResolverVisitor(compiler, element.getLibrary(), element); |
| 220 visitor.visit(tree); | 220 visitor.visit(tree); |
| 221 element.isResolved = true; | 221 element.isResolved = true; |
| 222 return element.type; | |
| 223 }); | 222 }); |
| 224 } | 223 } |
| 225 | 224 |
| 226 FunctionParameters resolveSignature(FunctionElement element) { | 225 FunctionParameters resolveSignature(FunctionElement element) { |
| 227 return measure(() => SignatureResolver.analyze(compiler, element)); | 226 return measure(() => SignatureResolver.analyze(compiler, element)); |
| 228 } | 227 } |
| 229 | 228 |
| 230 error(Node node, MessageKind kind, [arguments = const []]) { | 229 error(Node node, MessageKind kind, [arguments = const []]) { |
| 231 ResolutionError message = new ResolutionError(kind, arguments); | 230 ResolutionError message = new ResolutionError(kind, arguments); |
| 232 compiler.reportError(node, message); | 231 compiler.reportError(node, message); |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 } | 1046 } |
| 1048 | 1047 |
| 1049 Type resolveTypeRequired(TypeAnnotation node) { | 1048 Type resolveTypeRequired(TypeAnnotation node) { |
| 1050 bool old = typeRequired; | 1049 bool old = typeRequired; |
| 1051 typeRequired = true; | 1050 typeRequired = true; |
| 1052 Type result = resolveTypeAnnotation(node); | 1051 Type result = resolveTypeAnnotation(node); |
| 1053 typeRequired = old; | 1052 typeRequired = old; |
| 1054 return result; | 1053 return result; |
| 1055 } | 1054 } |
| 1056 | 1055 |
| 1057 Element resolveTypeName(node) { | 1056 Element resolveTypeName(TypeAnnotation node) { |
| 1058 Identifier typeName = node.typeName.asIdentifier(); | 1057 Identifier typeName = node.typeName.asIdentifier(); |
| 1059 Send send = node.typeName.asSend(); | 1058 Send send = node.typeName.asSend(); |
| 1060 if (send !== null) { | 1059 if (send !== null) { |
| 1061 typeName = send.selector; | 1060 typeName = send.selector; |
| 1062 } | 1061 } |
| 1063 if (typeName.source == Types.VOID) return compiler.types.voidType.element; | 1062 if (typeName.source == Types.VOID) return compiler.types.voidType.element; |
| 1064 if (typeName.source == Types.DYNAMIC || | 1063 if (typeName.source == Types.DYNAMIC || |
| 1065 typeName.source.stringValue == "var") { | 1064 typeName.source.stringValue == "var") { |
| 1066 return compiler.types.dynamicType.element; | 1065 return compiler.types.dynamicType.element; |
| 1067 } | 1066 } |
| 1068 if (send !== null) { | 1067 if (send !== null) { |
| 1069 Element e = context.lookup(send.receiver.asIdentifier().source); | 1068 Element e = context.lookup(send.receiver.asIdentifier().source); |
| 1070 if (e !== null && e.kind === ElementKind.PREFIX) { | 1069 if (e !== null && e.kind === ElementKind.PREFIX) { |
| 1071 // The receiver is a prefix. Lookup in the imported members. | 1070 // The receiver is a prefix. Lookup in the imported members. |
| 1072 PrefixElement prefix = e; | 1071 PrefixElement prefix = e; |
| 1073 return prefix.lookupLocalMember(typeName.source); | 1072 return prefix.lookupLocalMember(typeName.source); |
| 1074 } else if (e !== null && e.kind === ElementKind.CLASS) { | 1073 } else if (e !== null && e.kind === ElementKind.CLASS) { |
| 1075 // The receiver is the class part of a named constructor. | 1074 // The receiver is the class part of a named constructor. |
| 1076 return e; | 1075 return e; |
| 1077 } else { | 1076 } else { |
| 1078 error(send.receiver, MessageKind.CANNOT_RESOLVE); | 1077 return null; |
| 1079 } | 1078 } |
| 1080 } else { | 1079 } else { |
| 1081 return context.lookup(typeName.source); | 1080 return context.lookup(typeName.source); |
| 1082 } | 1081 } |
| 1083 } | 1082 } |
| 1084 | 1083 |
| 1085 Type resolveTypeAnnotation(TypeAnnotation node) { | 1084 Type resolveTypeAnnotation(TypeAnnotation node) { |
| 1085 Function report = typeRequired ? error : warning; |
| 1086 Element element = resolveTypeName(node); | 1086 Element element = resolveTypeName(node); |
| 1087 Type type; | 1087 Type type; |
| 1088 if (element === null) { | 1088 if (element === null) { |
| 1089 if (typeRequired) { | 1089 report(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); |
| 1090 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); | |
| 1091 } else { | |
| 1092 warning(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); | |
| 1093 } | |
| 1094 } else if (!element.impliesType()) { | 1090 } else if (!element.impliesType()) { |
| 1095 if (typeRequired) { | 1091 report(node, MessageKind.NOT_A_TYPE, [node.typeName]); |
| 1096 error(node, MessageKind.NOT_A_TYPE, [node.typeName]); | |
| 1097 } else { | |
| 1098 warning(node, MessageKind.NOT_A_TYPE, [node.typeName]); | |
| 1099 } | |
| 1100 } else { | 1092 } else { |
| 1101 if (element == compiler.types.voidType.element) { | 1093 if (element === compiler.types.voidType.element || |
| 1102 type = compiler.types.voidType; | 1094 element === compiler.types.dynamicType.element) { |
| 1103 } else if (element == compiler.types.dynamicType.element) { | 1095 type = element.computeType(compiler); |
| 1104 type = compiler.types.dynamicType; | |
| 1105 } else if (element.isClass()) { | 1096 } else if (element.isClass()) { |
| 1106 // TODO(ngeoffray): Should we also resolve typedef? | |
| 1107 ClassElement cls = element; | 1097 ClassElement cls = element; |
| 1108 compiler.resolver.toResolve.add(cls); | 1098 if (!cls.isResolved) compiler.resolveClass(cls); |
| 1109 LinkBuilder<Type> arguments = new LinkBuilder<Type>(); | 1099 LinkBuilder<Type> arguments = new LinkBuilder<Type>(); |
| 1110 if (node.typeArguments !== null) { | 1100 if (node.typeArguments !== null) { |
| 1101 int index = 0; |
| 1111 for (Link<Node> typeArguments = node.typeArguments.nodes; | 1102 for (Link<Node> typeArguments = node.typeArguments.nodes; |
| 1112 !typeArguments.isEmpty(); | 1103 !typeArguments.isEmpty(); |
| 1113 typeArguments = typeArguments.tail) { | 1104 typeArguments = typeArguments.tail) { |
| 1105 if (++index > cls.typeParameters.length) { |
| 1106 report(typeArguments.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); |
| 1107 } |
| 1114 arguments.addLast(resolveTypeAnnotation(typeArguments.head)); | 1108 arguments.addLast(resolveTypeAnnotation(typeArguments.head)); |
| 1115 } | 1109 } |
| 1110 if (index < cls.typeParameters.length) { |
| 1111 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); |
| 1112 } |
| 1116 } | 1113 } |
| 1117 type = new InterfaceType(element.name, element, arguments.toLink()); | 1114 type = new InterfaceType(cls.name, cls, arguments.toLink()); |
| 1118 } else if (element.isTypedef()) { | 1115 } else if (element.isTypedef()) { |
| 1119 // TODO(karlklose): implement typedefs. We return a fake type that the | 1116 // TODO(karlklose): implement typedefs. We return a fake type that the |
| 1120 // code generator can use to detect typedefs in is-checks. | 1117 // code generator can use to detect typedefs in is-checks. |
| 1121 type = new SimpleType(element.name, element); | 1118 type = new SimpleType(element.name, element); |
| 1122 } else { | 1119 } else { |
| 1123 type = element.computeType(compiler); | 1120 type = element.computeType(compiler); |
| 1124 } | 1121 } |
| 1125 } | 1122 } |
| 1126 return useType(node, type); | 1123 return useType(node, type); |
| 1127 } | 1124 } |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 | 1916 |
| 1920 TopScope(LibraryElement library) : super(null, library); | 1917 TopScope(LibraryElement library) : super(null, library); |
| 1921 Element lookup(SourceString name) { | 1918 Element lookup(SourceString name) { |
| 1922 return library.find(name); | 1919 return library.find(name); |
| 1923 } | 1920 } |
| 1924 | 1921 |
| 1925 Element add(Element element) { | 1922 Element add(Element element) { |
| 1926 throw "Cannot add an element in the top scope"; | 1923 throw "Cannot add an element in the top scope"; |
| 1927 } | 1924 } |
| 1928 } | 1925 } |
| OLD | NEW |