OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 String prefix; | 6 String prefix; |
7 Library library; | 7 Library library; |
8 LibraryImport(this.library, [this.prefix = null]); | 8 LibraryImport(this.library, [this.prefix = null]); |
9 } | 9 } |
10 | 10 |
11 /** Represents a Dart library. */ | 11 /** Represents a Dart library. */ |
12 class Library { | 12 class Library { |
13 final SourceFile baseSource; | 13 final SourceFile baseSource; |
14 Map<String, DefinedType> types; | 14 Map<String, Type> types; |
15 List<LibraryImport> imports; | 15 List<LibraryImport> imports; |
16 String sourceDir; | 16 String sourceDir; |
17 String name; | 17 String name; |
18 List<SourceFile> natives; | 18 List<SourceFile> natives; |
19 List<SourceFile> sources; | 19 List<SourceFile> sources; |
20 | 20 |
21 Map<String, MemberSet> _privateMembers; | 21 Map<String, MemberSet> _privateMembers; |
22 | 22 |
23 /** The type that holds top level types in the library. */ | 23 /** The type that holds top level types in the library. */ |
24 DefinedType topType; | 24 DefinedType topType; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 final def = new FunctionTypeDefinition(func, null, func.span); | 114 final def = new FunctionTypeDefinition(func, null, func.span); |
115 final type = new DefinedType(name, this, def, false); | 115 final type = new DefinedType(name, this, def, false); |
116 type.addMethod('\$call', func); | 116 type.addMethod('\$call', func); |
117 type.members['\$call'].resolve(inType); | 117 type.members['\$call'].resolve(inType); |
118 // Function types implement the Function interface. | 118 // Function types implement the Function interface. |
119 type.interfaces = [world.functionType]; | 119 type.interfaces = [world.functionType]; |
120 return type; | 120 return type; |
121 } | 121 } |
122 | 122 |
123 /** Adds a type to the library. */ | 123 /** Adds a type to the library. */ |
124 DefinedType addType(String name, Node definition, bool isClass) { | 124 Type addType(String name, Node definition, bool isClass) { |
125 if (types.containsKey(name)) { | 125 if (types.containsKey(name)) { |
126 var existingType = types[name]; | 126 var existingType = types[name]; |
127 if (isCore && existingType.definition == null) { | 127 if (isCore && existingType.definition == null) { |
128 // TODO(jimhug): Validate compatibility with natives. | 128 // TODO(jimhug): Validate compatibility with natives. |
129 existingType.setDefinition(definition); | 129 existingType.setDefinition(definition); |
130 } else { | 130 } else { |
131 world.warning('duplicate definition of $name', definition.span); | 131 world.warning('duplicate definition of $name', definition.span); |
132 } | 132 } |
133 } else { | 133 } else { |
134 types[name] = new DefinedType(name, this, definition, isClass); | 134 types[name] = new DefinedType(name, this, definition, isClass); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 var visitor = new _LibraryVisitor(this); | 244 var visitor = new _LibraryVisitor(this); |
245 visitor.addSource(baseSource); | 245 visitor.addSource(baseSource); |
246 } | 246 } |
247 | 247 |
248 toString() => baseSource.filename; | 248 toString() => baseSource.filename; |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 class _LibraryVisitor implements TreeVisitor { | 252 class _LibraryVisitor implements TreeVisitor { |
253 final Library library; | 253 final Library library; |
254 DefinedType currentType; | 254 Type currentType; |
255 List<SourceFile> sources; | 255 List<SourceFile> sources; |
256 | 256 |
257 bool seenImport = false; | 257 bool seenImport = false; |
258 bool seenSource = false; | 258 bool seenSource = false; |
259 bool seenResource = false; | 259 bool seenResource = false; |
260 bool isTop = true; | 260 bool isTop = true; |
261 | 261 |
262 _LibraryVisitor(this.library) { | 262 _LibraryVisitor(this.library) { |
263 currentType = library.topType; | 263 currentType = library.topType; |
264 sources = []; | 264 sources = []; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 443 |
444 void visitFunctionDefinition(FunctionDefinition node) { | 444 void visitFunctionDefinition(FunctionDefinition node) { |
445 currentType.addMethod(node.name.name, node); | 445 currentType.addMethod(node.name.name, node); |
446 } | 446 } |
447 | 447 |
448 void visitFunctionTypeDefinition(FunctionTypeDefinition node) { | 448 void visitFunctionTypeDefinition(FunctionTypeDefinition node) { |
449 var type = library.addType(node.func.name.name, node, false); | 449 var type = library.addType(node.func.name.name, node, false); |
450 type.addMethod('\$call', node.func); | 450 type.addMethod('\$call', node.func); |
451 } | 451 } |
452 } | 452 } |
OLD | NEW |