Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 10105031: Check number of type arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove accidental edits. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/enqueue.dart ('k') | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 (send !== null) { 1063 if (send !== null) {
1065 Element e = context.lookup(send.receiver.asIdentifier().source); 1064 Element e = context.lookup(send.receiver.asIdentifier().source);
1066 if (e !== null && e.kind === ElementKind.PREFIX) { 1065 if (e !== null && e.kind === ElementKind.PREFIX) {
1067 // The receiver is a prefix. Lookup in the imported members. 1066 // The receiver is a prefix. Lookup in the imported members.
1068 PrefixElement prefix = e; 1067 PrefixElement prefix = e;
1069 return prefix.lookupLocalMember(typeName.source); 1068 return prefix.lookupLocalMember(typeName.source);
1070 } else if (e !== null && e.kind === ElementKind.CLASS) { 1069 } else if (e !== null && e.kind === ElementKind.CLASS) {
1071 // The receiver is the class part of a named constructor. 1070 // The receiver is the class part of a named constructor.
1072 return e; 1071 return e;
1073 } else { 1072 } else {
1074 error(send.receiver, MessageKind.CANNOT_RESOLVE); 1073 return null;
1075 } 1074 }
1076 } else { 1075 } else {
1077 return context.lookup(typeName.source); 1076 return context.lookup(typeName.source);
1078 } 1077 }
1079 } 1078 }
1080 1079
1081 Type resolveTypeAnnotation(TypeAnnotation node) { 1080 Type resolveTypeAnnotation(TypeAnnotation node) {
1081 Function report = typeRequired ? error : warning;
1082 Element element = resolveTypeName(node); 1082 Element element = resolveTypeName(node);
1083 Type type; 1083 Type type;
1084 if (element === null) { 1084 if (element === null) {
1085 if (typeRequired) { 1085 report(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
1086 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
1087 } else {
1088 warning(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
1089 }
1090 } else if (!element.impliesType()) { 1086 } else if (!element.impliesType()) {
1091 if (typeRequired) { 1087 report(node, MessageKind.NOT_A_TYPE, [node.typeName]);
1092 error(node, MessageKind.NOT_A_TYPE, [node.typeName]);
1093 } else {
1094 warning(node, MessageKind.NOT_A_TYPE, [node.typeName]);
1095 }
1096 } else { 1088 } else {
1097 if (element == compiler.types.voidType.element) { 1089 if (element === compiler.types.voidType.element ||
1098 type = compiler.types.voidType; 1090 element === compiler.types.dynamicType.element) {
1099 } else if (element == compiler.types.dynamicType.element) { 1091 type = element.computeType(compiler);
1100 type = compiler.types.dynamicType;
1101 } else if (element.isClass()) { 1092 } else if (element.isClass()) {
1102 // TODO(ngeoffray): Should we also resolve typedef?
1103 ClassElement cls = element; 1093 ClassElement cls = element;
1104 compiler.resolver.toResolve.add(cls); 1094 if (!cls.isResolved) compiler.resolveClass(cls);
1105 LinkBuilder<Type> arguments = new LinkBuilder<Type>(); 1095 LinkBuilder<Type> arguments = new LinkBuilder<Type>();
1106 if (node.typeArguments !== null) { 1096 if (node.typeArguments !== null) {
1097 int index = 0;
1107 for (Link<Node> typeArguments = node.typeArguments.nodes; 1098 for (Link<Node> typeArguments = node.typeArguments.nodes;
1108 !typeArguments.isEmpty(); 1099 !typeArguments.isEmpty();
1109 typeArguments = typeArguments.tail) { 1100 typeArguments = typeArguments.tail) {
1101 if (++index > cls.typeParameters.length) {
1102 report(typeArguments.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT);
1103 }
1110 arguments.addLast(resolveTypeAnnotation(typeArguments.head)); 1104 arguments.addLast(resolveTypeAnnotation(typeArguments.head));
1111 } 1105 }
1106 if (index < cls.typeParameters.length) {
1107 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT);
1108 }
1112 } 1109 }
1113 type = new InterfaceType(element.name, element, arguments.toLink()); 1110 type = new InterfaceType(cls.name, cls, arguments.toLink());
1114 } else if (element.isTypedef()) { 1111 } else if (element.isTypedef()) {
1115 // TODO(karlklose): implement typedefs. We return a fake type that the 1112 // TODO(karlklose): implement typedefs. We return a fake type that the
1116 // code generator can use to detect typedefs in is-checks. 1113 // code generator can use to detect typedefs in is-checks.
1117 type = new InterfaceType(element.name, element); 1114 type = new InterfaceType(element.name, element);
1118 } else { 1115 } else {
1119 type = element.computeType(compiler); 1116 type = element.computeType(compiler);
1120 } 1117 }
1121 } 1118 }
1122 return useType(node, type); 1119 return useType(node, type);
1123 } 1120 }
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 1913
1917 TopScope(LibraryElement library) : super(null, library); 1914 TopScope(LibraryElement library) : super(null, library);
1918 Element lookup(SourceString name) { 1915 Element lookup(SourceString name) {
1919 return library.find(name); 1916 return library.find(name);
1920 } 1917 }
1921 1918
1922 Element add(Element newElement) { 1919 Element add(Element newElement) {
1923 throw "Cannot add an element in the top scope"; 1920 throw "Cannot add an element in the top scope";
1924 } 1921 }
1925 } 1922 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/enqueue.dart ('k') | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698