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 '../errors.dart' show internalError; | 9 import '../deprecated_problems.dart' show deprecated_internalProblem; |
10 | 10 |
11 import '../export.dart' show Export; | 11 import '../export.dart' show Export; |
12 | 12 |
13 import '../loader.dart' show Loader; | 13 import '../loader.dart' show Loader; |
14 | 14 |
15 import '../messages.dart' show nit, warning; | 15 import '../messages.dart' show deprecated_nit, deprecated_warning; |
16 | 16 |
17 import '../util/relativize.dart' show relativizeUri; | 17 import '../util/relativize.dart' show relativizeUri; |
18 | 18 |
19 import 'builder.dart' | 19 import 'builder.dart' |
20 show | 20 show |
21 Builder, | 21 Builder, |
22 ClassBuilder, | 22 ClassBuilder, |
23 DynamicTypeBuilder, | 23 DynamicTypeBuilder, |
24 PrefixBuilder, | 24 PrefixBuilder, |
25 Scope, | 25 Scope, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 Uri get uri; | 61 Uri get uri; |
62 | 62 |
63 Builder addBuilder(String name, Builder builder, int charOffset); | 63 Builder addBuilder(String name, Builder builder, int charOffset); |
64 | 64 |
65 void addExporter( | 65 void addExporter( |
66 LibraryBuilder exporter, List<Combinator> combinators, int charOffset) { | 66 LibraryBuilder exporter, List<Combinator> combinators, int charOffset) { |
67 exporters.add(new Export(exporter, this, combinators, charOffset)); | 67 exporters.add(new Export(exporter, this, combinators, charOffset)); |
68 } | 68 } |
69 | 69 |
70 /// See `Loader.addCompileTimeError` for an explanation of the arguments | 70 /// See `Loader.deprecated_addCompileTimeError` for an explanation of the |
71 /// passed to this method. | 71 /// arguments passed to this method. |
72 /// | 72 /// |
73 /// If [fileUri] is null, it defaults to `this.fileUri`. | 73 /// If [fileUri] is null, it defaults to `this.fileUri`. |
74 void addCompileTimeError(int charOffset, Object message, | 74 void deprecated_addCompileTimeError(int charOffset, Object message, |
75 {Uri fileUri, bool silent: false, bool wasHandled: false}) { | 75 {Uri fileUri, bool silent: false, bool wasHandled: false}) { |
76 hasCompileTimeErrors = true; | 76 hasCompileTimeErrors = true; |
77 loader.addCompileTimeError(fileUri ?? this.fileUri, charOffset, message, | 77 loader.deprecated_addCompileTimeError( |
| 78 fileUri ?? this.fileUri, charOffset, message, |
78 silent: silent, wasHandled: wasHandled); | 79 silent: silent, wasHandled: wasHandled); |
79 } | 80 } |
80 | 81 |
81 void addWarning(int charOffset, Object message, | 82 void deprecated_addWarning(int charOffset, Object message, |
82 {Uri fileUri, bool silent: false}) { | 83 {Uri fileUri, bool silent: false}) { |
83 fileUri ??= this.fileUri; | 84 fileUri ??= this.fileUri; |
84 if (!silent) { | 85 if (!silent) { |
85 warning(fileUri, charOffset, message); | 86 deprecated_warning(fileUri, charOffset, message); |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 void addNit(int charOffset, Object message, | 90 void deprecated_addNit(int charOffset, Object message, |
90 {Uri fileUri, bool silent: false}) { | 91 {Uri fileUri, bool silent: false}) { |
91 fileUri ??= this.fileUri; | 92 fileUri ??= this.fileUri; |
92 if (!silent) { | 93 if (!silent) { |
93 nit(fileUri, charOffset, message); | 94 deprecated_nit(fileUri, charOffset, message); |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 /// Returns true if the export scope was modified. | 98 /// Returns true if the export scope was modified. |
98 bool addToExportScope(String name, Builder member) { | 99 bool addToExportScope(String name, Builder member) { |
99 if (name.startsWith("_")) return false; | 100 if (name.startsWith("_")) return false; |
100 if (member is PrefixBuilder) return false; | 101 if (member is PrefixBuilder) return false; |
101 Map<String, Builder> map = | 102 Map<String, Builder> map = |
102 member.isSetter ? exports.setters : exports.local; | 103 member.isSetter ? exports.setters : exports.local; |
103 Builder existing = map[name]; | 104 Builder existing = map[name]; |
(...skipping 28 matching lines...) Expand all Loading... |
132 /// It is an error if no such class is found, or if the class doesn't have a | 133 /// It is an error if no such class is found, or if the class doesn't have a |
133 /// matching constructor (or factory). | 134 /// matching constructor (or factory). |
134 /// | 135 /// |
135 /// If [constructorName] is null or the empty string, it's assumed to be an | 136 /// If [constructorName] is null or the empty string, it's assumed to be an |
136 /// unnamed constructor. it's an error if [constructorName] starts with | 137 /// unnamed constructor. it's an error if [constructorName] starts with |
137 /// `"_"`, and [bypassLibraryPrivacy] is false. | 138 /// `"_"`, and [bypassLibraryPrivacy] is false. |
138 Builder getConstructor(String className, | 139 Builder getConstructor(String className, |
139 {String constructorName, bool bypassLibraryPrivacy: false}) { | 140 {String constructorName, bool bypassLibraryPrivacy: false}) { |
140 constructorName ??= ""; | 141 constructorName ??= ""; |
141 if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { | 142 if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { |
142 throw internalError("Internal error: Can't access private constructor " | 143 throw deprecated_internalProblem( |
| 144 "Internal error: Can't access private constructor " |
143 "'$constructorName'."); | 145 "'$constructorName'."); |
144 } | 146 } |
145 Builder cls = | 147 Builder cls = |
146 (bypassLibraryPrivacy ? scope : exports).lookup(className, -1, null); | 148 (bypassLibraryPrivacy ? scope : exports).lookup(className, -1, null); |
147 if (cls is ClassBuilder) { | 149 if (cls is ClassBuilder) { |
148 // TODO(ahe): This code is similar to code in `endNewExpression` in | 150 // TODO(ahe): This code is similar to code in `endNewExpression` in |
149 // `body_builder.dart`, try to share it. | 151 // `body_builder.dart`, try to share it. |
150 Builder constructor = | 152 Builder constructor = |
151 cls.findConstructorOrFactory(constructorName, -1, null, this); | 153 cls.findConstructorOrFactory(constructorName, -1, null, this); |
152 if (constructor == null) { | 154 if (constructor == null) { |
153 // Fall-through to internal error below. | 155 // Fall-through to internal error below. |
154 } else if (constructor.isConstructor) { | 156 } else if (constructor.isConstructor) { |
155 if (!cls.isAbstract) { | 157 if (!cls.isAbstract) { |
156 return constructor; | 158 return constructor; |
157 } | 159 } |
158 } else if (constructor.isFactory) { | 160 } else if (constructor.isFactory) { |
159 return constructor; | 161 return constructor; |
160 } | 162 } |
161 } | 163 } |
162 throw internalError("Internal error: No constructor named" | 164 throw deprecated_internalProblem("Internal error: No constructor named" |
163 " '$className::$constructorName' in '$uri'."); | 165 " '$className::$constructorName' in '$uri'."); |
164 } | 166 } |
165 | 167 |
166 int finishTypeVariables(ClassBuilder object) => 0; | 168 int finishTypeVariables(ClassBuilder object) => 0; |
167 | 169 |
168 void becomeCoreLibrary(dynamicType, voidType) { | 170 void becomeCoreLibrary(dynamicType, voidType) { |
169 addBuilder("dynamic", | 171 addBuilder("dynamic", |
170 new DynamicTypeBuilder<T, dynamic>(dynamicType, this, -1), -1); | 172 new DynamicTypeBuilder<T, dynamic>(dynamicType, this, -1), -1); |
171 addBuilder("void", new VoidTypeBuilder<T, dynamic>(voidType, this, -1), -1); | 173 addBuilder("void", new VoidTypeBuilder<T, dynamic>(voidType, this, -1), -1); |
172 } | 174 } |
173 | 175 |
174 void forEach(void f(String name, Builder builder)) { | 176 void forEach(void f(String name, Builder builder)) { |
175 scope.forEach(f); | 177 scope.forEach(f); |
176 } | 178 } |
177 | 179 |
178 /// Don't use for scope lookup. Only use when an element is known to exist | 180 /// Don't use for scope lookup. Only use when an element is known to exist |
179 /// (and not a setter). | 181 /// (and not a setter). |
180 Builder operator [](String name) { | 182 Builder operator [](String name) { |
181 return scope.local[name] ?? internalError("Not found: '$name'."); | 183 return scope.local[name] ?? |
| 184 deprecated_internalProblem("Not found: '$name'."); |
182 } | 185 } |
183 | 186 |
184 Builder lookup(String name, int charOffset, Uri fileUri) { | 187 Builder lookup(String name, int charOffset, Uri fileUri) { |
185 return scope.lookup(name, charOffset, fileUri); | 188 return scope.lookup(name, charOffset, fileUri); |
186 } | 189 } |
187 } | 190 } |
OLD | NEW |