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 class LibraryImport { | 5 class LibraryImport { |
6 final String prefix; | 6 final String prefix; |
7 final Library library; | 7 final Library library; |
8 final SourceSpan span; | 8 final SourceSpan span; |
9 LibraryImport(this.library, [this.prefix, this.span]); | 9 LibraryImport(this.library, [this.prefix, this.span]); |
10 } | 10 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } else { | 111 } else { |
112 mset.members.add(member); | 112 mset.members.add(member); |
113 } | 113 } |
114 } else { | 114 } else { |
115 world._addMember(member); | 115 world._addMember(member); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 // TODO(jimhug): Cache and share the types as interfaces! | 119 // TODO(jimhug): Cache and share the types as interfaces! |
120 Type getOrAddFunctionType(Element enclosingElement, String name, | 120 Type getOrAddFunctionType(Element enclosingElement, String name, |
121 FunctionDefinition func) { | 121 FunctionDefinition func, MethodData data) { |
122 // TODO(jimhug): This is redundant now that FunctionDef has type params. | 122 // TODO(jimhug): This is redundant now that FunctionDef has type params. |
123 final def = new FunctionTypeDefinition(func, null, func.span); | 123 final def = new FunctionTypeDefinition(func, null, func.span); |
124 final type = new DefinedType(name, this, def, false); | 124 final type = new DefinedType(name, this, def, false); |
125 type.addMethod(':call', func); | 125 type.addMethod(':call', func); |
126 var m = type.members[':call']; | 126 var m = type.members[':call']; |
127 m.enclosingElement = enclosingElement; | 127 m.enclosingElement = enclosingElement; |
128 m.resolve(); | 128 m.resolve(); |
| 129 m._methodData = data; |
129 // Function types implement the Function interface. | 130 // Function types implement the Function interface. |
130 type.interfaces = [world.functionType]; | 131 type.interfaces = [world.functionType]; |
131 return type; | 132 return type; |
132 } | 133 } |
133 | 134 |
134 /** Adds a type to the library. */ | 135 /** Adds a type to the library. */ |
135 DefinedType addType(String name, Node definition, bool isClass) { | 136 DefinedType addType(String name, Node definition, bool isClass) { |
136 if (types.containsKey(name)) { | 137 if (types.containsKey(name)) { |
137 var existingType = types[name]; | 138 var existingType = types[name]; |
138 if ((isCore || isCoreImpl) && existingType.definition == null) { | 139 if ((isCore || isCoreImpl) && existingType.definition == null) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 if (ret != null && ret != newRet) { | 192 if (ret != null && ret != newRet) { |
192 world.error('conflicting types for "$name"', ret.span, newRet.span); | 193 world.error('conflicting types for "$name"', ret.span, newRet.span); |
193 } else { | 194 } else { |
194 ret = newRet; | 195 ret = newRet; |
195 } | 196 } |
196 } | 197 } |
197 } | 198 } |
198 return ret; | 199 return ret; |
199 } | 200 } |
200 | 201 |
201 Type resolveType(TypeReference node, bool typeErrors) { | 202 |
| 203 // TODO(jimhug): Why is it okay to assume node is NameTypeReference in here? |
| 204 Type resolveType(TypeReference node, bool typeErrors, bool allowTypeParams) { |
202 if (node == null) return world.varType; | 205 if (node == null) return world.varType; |
203 | 206 |
204 if (node.type != null) return node.type; | 207 var ret = findType(node); |
205 | 208 |
206 node.type = findType(node); | 209 if (ret == null) { |
207 | |
208 if (node.type == null) { | |
209 var message = 'cannot find type ${_getDottedName(node)}'; | 210 var message = 'cannot find type ${_getDottedName(node)}'; |
210 if (typeErrors) { | 211 if (typeErrors) { |
211 world.error(message, node.span); | 212 world.error(message, node.span); |
212 node.type = world.objectType; | 213 return world.objectType; |
213 } else { | 214 } else { |
214 world.warning(message, node.span); | 215 world.warning(message, node.span); |
215 node.type = world.varType; | 216 return world.varType; |
216 } | 217 } |
217 } | 218 } |
218 return node.type; | 219 return ret; |
219 } | 220 } |
220 | 221 |
221 static String _getDottedName(NameTypeReference type) { | 222 static String _getDottedName(NameTypeReference type) { |
222 if (type.names != null) { | 223 if (type.names != null) { |
223 var names = map(type.names, (n) => n.name); | 224 var names = map(type.names, (n) => n.name); |
224 return type.name.name + '.' + Strings.join(names, '.'); | 225 return type.name.name + '.' + Strings.join(names, '.'); |
225 } else { | 226 } else { |
226 return type.name.name; | 227 return type.name.name; |
227 } | 228 } |
228 } | 229 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 library.sources.add(source); | 355 library.sources.add(source); |
355 final parser = new Parser(source, diet: options.dietParse); | 356 final parser = new Parser(source, diet: options.dietParse); |
356 final unit = parser.compilationUnit(); | 357 final unit = parser.compilationUnit(); |
357 | 358 |
358 unit.forEach((def) => def.visit(this)); | 359 unit.forEach((def) => def.visit(this)); |
359 | 360 |
360 assert(sources.length == 0 || isTop); | 361 assert(sources.length == 0 || isTop); |
361 isTop = false; | 362 isTop = false; |
362 var newSources = sources; | 363 var newSources = sources; |
363 sources = []; | 364 sources = []; |
364 for (var source in newSources) { | 365 for (var newSource in newSources) { |
365 addSource(source); | 366 addSource(newSource); |
366 } | 367 } |
367 } | 368 } |
368 | 369 |
369 void visitDirectiveDefinition(DirectiveDefinition node) { | 370 void visitDirectiveDefinition(DirectiveDefinition node) { |
370 if (!isTop) { | 371 if (!isTop) { |
371 world.error('directives not allowed in sourced file', node.span); | 372 world.error('directives not allowed in sourced file', node.span); |
372 return; | 373 return; |
373 } | 374 } |
374 | 375 |
375 var name; | 376 var name; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 511 |
511 void visitFunctionDefinition(FunctionDefinition node) { | 512 void visitFunctionDefinition(FunctionDefinition node) { |
512 currentType.addMethod(node.name.name, node); | 513 currentType.addMethod(node.name.name, node); |
513 } | 514 } |
514 | 515 |
515 void visitFunctionTypeDefinition(FunctionTypeDefinition node) { | 516 void visitFunctionTypeDefinition(FunctionTypeDefinition node) { |
516 var type = library.addType(node.func.name.name, node, false); | 517 var type = library.addType(node.func.name.name, node, false); |
517 type.addMethod(':call', node.func); | 518 type.addMethod(':call', node.func); |
518 } | 519 } |
519 } | 520 } |
OLD | NEW |