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