OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.prefix_builder; | 5 library fasta.prefix_builder; |
6 | 6 |
7 import 'builder.dart' show | 7 import 'builder.dart' show |
8 Builder, | 8 Builder, |
9 LibraryBuilder, | 9 LibraryBuilder, |
10 MemberBuilder; | 10 MemberBuilder; |
11 | 11 |
| 12 import '../messages.dart' show |
| 13 warning; |
| 14 |
12 import 'package:kernel/ast.dart' show | 15 import 'package:kernel/ast.dart' show |
13 Member; | 16 Member; |
14 | 17 |
15 import '../dill/dill_member_builder.dart' show | 18 import '../dill/dill_member_builder.dart' show |
16 DillMemberBuilder; | 19 DillMemberBuilder; |
17 | 20 |
18 import '../errors.dart' show | 21 import '../errors.dart' show |
19 internalError; | 22 internalError; |
20 | 23 |
21 class PrefixBuilder extends Builder { | 24 class PrefixBuilder extends Builder { |
22 final String name; | 25 final String name; |
23 | 26 |
24 final Map<String, Builder> exports; | 27 final Map<String, Builder> exports; |
25 | 28 |
26 final LibraryBuilder parent; | 29 final LibraryBuilder parent; |
27 | 30 |
28 PrefixBuilder(this.name, this.exports, LibraryBuilder parent, int charOffset) | 31 PrefixBuilder(this.name, this.exports, LibraryBuilder parent, int charOffset) |
29 : parent = parent, super(parent, charOffset, parent.fileUri); | 32 : parent = parent, super(parent, charOffset, parent.fileUri); |
30 | 33 |
31 Member findTopLevelMember(String name) { | 34 Member findTopLevelMember(String name) { |
32 // TODO(ahe): Move this to KernelPrefixBuilder. | 35 // TODO(ahe): Move this to KernelPrefixBuilder. |
33 Builder builder = exports[name]; | 36 Builder builder = exports[name]; |
34 if (builder == null) { | 37 if (builder == null) { |
35 // TODO(ahe): Report error? | 38 warning(parent.fileUri, -1, |
36 print("${this.name} has no member named $name"); | 39 "'${this.name}' has no member named '$name'."); |
37 } | 40 } |
38 if (builder is DillMemberBuilder) { | 41 if (builder is DillMemberBuilder) { |
39 return builder.member.isInstanceMember | 42 return builder.member.isInstanceMember |
40 ? internalError("Unexpected instance member in export scope") | 43 ? internalError("Unexpected instance member in export scope") |
41 : builder.member; | 44 : builder.member; |
42 } else if (builder is MemberBuilder) { | 45 } else if (builder is MemberBuilder) { |
43 return builder.target; | 46 return builder.target; |
44 } else { | 47 } else { |
45 return null; | 48 return null; |
46 } | 49 } |
47 } | 50 } |
48 | 51 |
49 Builder combineAmbiguousImport(String name, Builder other, | 52 Builder combineAmbiguousImport(String name, Builder other, |
50 LibraryBuilder library) { | 53 LibraryBuilder library) { |
51 if (other is PrefixBuilder) { | 54 if (other is PrefixBuilder) { |
52 /// Handles the case where the same prefix is used for different imports. | 55 /// Handles the case where the same prefix is used for different imports. |
53 other.exports.forEach((String name, Builder member) { | 56 other.exports.forEach((String name, Builder member) { |
54 Builder existing = exports[name]; | 57 Builder existing = exports[name]; |
55 if (existing != null) { | 58 if (existing != null) { |
56 member = existing.combineAmbiguousImport(name, member, library); | 59 member = existing.combineAmbiguousImport(name, member, library); |
57 } | 60 } |
58 exports[name] = member; | 61 exports[name] = member; |
59 }); | 62 }); |
60 return this; | 63 return this; |
61 } | 64 } |
62 return super.combineAmbiguousImport(name, other, library); | 65 return super.combineAmbiguousImport(name, other, library); |
63 } | 66 } |
64 } | 67 } |
OLD | NEW |