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.library_builder; | 5 library fasta.library_builder; |
6 | 6 |
7 import '../combinator.dart' show Combinator; | 7 import '../combinator.dart' show Combinator; |
8 | 8 |
9 import '../problems.dart' show internalProblem; | 9 import '../problems.dart' show internalProblem; |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 DynamicTypeBuilder, | 30 DynamicTypeBuilder, |
31 PrefixBuilder, | 31 PrefixBuilder, |
32 Scope, | 32 Scope, |
33 ScopeBuilder, | 33 ScopeBuilder, |
34 TypeBuilder, | 34 TypeBuilder, |
35 VoidTypeBuilder; | 35 VoidTypeBuilder; |
36 | 36 |
37 abstract class LibraryBuilder<T extends TypeBuilder, R> extends Builder { | 37 abstract class LibraryBuilder<T extends TypeBuilder, R> extends Builder { |
38 final Scope scope; | 38 final Scope scope; |
39 | 39 |
40 final Scope exports; | 40 final Scope exportScope; |
41 | 41 |
42 final ScopeBuilder scopeBuilder; | 42 final ScopeBuilder scopeBuilder; |
43 | 43 |
44 final ScopeBuilder exportScopeBuilder; | 44 final ScopeBuilder exportScopeBuilder; |
45 | 45 |
46 final List<Export> exporters = <Export>[]; | 46 final List<Export> exporters = <Export>[]; |
47 | 47 |
48 final Uri fileUri; | 48 final Uri fileUri; |
49 | 49 |
50 final String relativeFileUri; | 50 final String relativeFileUri; |
51 | 51 |
52 LibraryBuilder partOfLibrary; | 52 LibraryBuilder partOfLibrary; |
53 | 53 |
54 /// True if a compile-time error has been reported in this library. | 54 /// True if a compile-time error has been reported in this library. |
55 bool hasCompileTimeErrors = false; | 55 bool hasCompileTimeErrors = false; |
56 | 56 |
57 bool mayImplementRestrictedTypes = false; | 57 bool mayImplementRestrictedTypes = false; |
58 | 58 |
59 LibraryBuilder(Uri fileUri, this.scope, this.exports) | 59 LibraryBuilder(Uri fileUri, this.scope, this.exportScope) |
60 : fileUri = fileUri, | 60 : fileUri = fileUri, |
61 relativeFileUri = relativizeUri(fileUri), | 61 relativeFileUri = relativizeUri(fileUri), |
62 scopeBuilder = new ScopeBuilder(scope), | 62 scopeBuilder = new ScopeBuilder(scope), |
63 exportScopeBuilder = new ScopeBuilder(exports), | 63 exportScopeBuilder = new ScopeBuilder(exportScope), |
64 super(null, -1, fileUri); | 64 super(null, -1, fileUri); |
65 | 65 |
66 Loader get loader; | 66 Loader get loader; |
67 | 67 |
68 Uri get uri; | 68 Uri get uri; |
69 | 69 |
70 Builder addBuilder(String name, Builder builder, int charOffset); | 70 Builder addBuilder(String name, Builder builder, int charOffset); |
71 | 71 |
72 void addExporter( | 72 void addExporter( |
73 LibraryBuilder exporter, List<Combinator> combinators, int charOffset) { | 73 LibraryBuilder exporter, List<Combinator> combinators, int charOffset) { |
(...skipping 22 matching lines...) Expand all Loading... |
96 if (!silent) { | 96 if (!silent) { |
97 nit(message, charOffset, uri); | 97 nit(message, charOffset, uri); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 /// Returns true if the export scope was modified. | 101 /// Returns true if the export scope was modified. |
102 bool addToExportScope(String name, Builder member) { | 102 bool addToExportScope(String name, Builder member) { |
103 if (name.startsWith("_")) return false; | 103 if (name.startsWith("_")) return false; |
104 if (member is PrefixBuilder) return false; | 104 if (member is PrefixBuilder) return false; |
105 Map<String, Builder> map = | 105 Map<String, Builder> map = |
106 member.isSetter ? exports.setters : exports.local; | 106 member.isSetter ? exportScope.setters : exportScope.local; |
107 Builder existing = map[name]; | 107 Builder existing = map[name]; |
108 if (existing == member) return false; | 108 if (existing == member) return false; |
109 if (existing != null) { | 109 if (existing != null) { |
110 Builder result = | 110 Builder result = |
111 buildAmbiguousBuilder(name, existing, member, -1, isExport: true); | 111 buildAmbiguousBuilder(name, existing, member, -1, isExport: true); |
112 map[name] = result; | 112 map[name] = result; |
113 return result != existing; | 113 return result != existing; |
114 } else { | 114 } else { |
115 map[name] = member; | 115 map[name] = member; |
116 } | 116 } |
(...skipping 25 matching lines...) Expand all Loading... |
142 Builder getConstructor(String className, | 142 Builder getConstructor(String className, |
143 {String constructorName, bool bypassLibraryPrivacy: false}) { | 143 {String constructorName, bool bypassLibraryPrivacy: false}) { |
144 constructorName ??= ""; | 144 constructorName ??= ""; |
145 if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { | 145 if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { |
146 return internalProblem( | 146 return internalProblem( |
147 templateInternalProblemPrivateConstructorAccess | 147 templateInternalProblemPrivateConstructorAccess |
148 .withArguments(constructorName), | 148 .withArguments(constructorName), |
149 -1, | 149 -1, |
150 null); | 150 null); |
151 } | 151 } |
152 Builder cls = | 152 Builder cls = (bypassLibraryPrivacy ? scope : exportScope) |
153 (bypassLibraryPrivacy ? scope : exports).lookup(className, -1, null); | 153 .lookup(className, -1, null); |
154 if (cls is ClassBuilder) { | 154 if (cls is ClassBuilder) { |
155 // TODO(ahe): This code is similar to code in `endNewExpression` in | 155 // TODO(ahe): This code is similar to code in `endNewExpression` in |
156 // `body_builder.dart`, try to share it. | 156 // `body_builder.dart`, try to share it. |
157 Builder constructor = | 157 Builder constructor = |
158 cls.findConstructorOrFactory(constructorName, -1, null, this); | 158 cls.findConstructorOrFactory(constructorName, -1, null, this); |
159 if (constructor == null) { | 159 if (constructor == null) { |
160 // Fall-through to internal error below. | 160 // Fall-through to internal error below. |
161 } else if (constructor.isConstructor) { | 161 } else if (constructor.isConstructor) { |
162 if (!cls.isAbstract) { | 162 if (!cls.isAbstract) { |
163 return constructor; | 163 return constructor; |
(...skipping 29 matching lines...) Expand all Loading... |
193 templateInternalProblemNotFoundIn.withArguments( | 193 templateInternalProblemNotFoundIn.withArguments( |
194 name, relativeFileUri), | 194 name, relativeFileUri), |
195 -1, | 195 -1, |
196 null); | 196 null); |
197 } | 197 } |
198 | 198 |
199 Builder lookup(String name, int charOffset, Uri fileUri) { | 199 Builder lookup(String name, int charOffset, Uri fileUri) { |
200 return scope.lookup(name, charOffset, fileUri); | 200 return scope.lookup(name, charOffset, fileUri); |
201 } | 201 } |
202 } | 202 } |
OLD | NEW |