| 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.scope; | 5 library fasta.scope; |
| 6 | 6 |
| 7 import 'builder/builder.dart' show Builder, TypeVariableBuilder; | 7 import 'builder/builder.dart' show Builder, TypeVariableBuilder; |
| 8 | 8 |
| 9 import 'errors.dart' show InputError, internalError; | 9 import 'deprecated_problems.dart' |
| 10 show deprecated_InputError, deprecated_internalProblem; |
| 10 | 11 |
| 11 class MutableScope { | 12 class MutableScope { |
| 12 /// Names declared in this scope. | 13 /// Names declared in this scope. |
| 13 Map<String, Builder> local; | 14 Map<String, Builder> local; |
| 14 | 15 |
| 15 /// Setters declared in this scope. | 16 /// Setters declared in this scope. |
| 16 Map<String, Builder> setters; | 17 Map<String, Builder> setters; |
| 17 | 18 |
| 18 /// The scope that this scope is nested within, or `null` if this is the top | 19 /// The scope that this scope is nested within, or `null` if this is the top |
| 19 /// level scope. | 20 /// level scope. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 42 isModifiable: isModifiable); | 43 isModifiable: isModifiable); |
| 43 | 44 |
| 44 Scope.immutable() | 45 Scope.immutable() |
| 45 : this(const <String, Builder>{}, const <String, Builder>{}, null, | 46 : this(const <String, Builder>{}, const <String, Builder>{}, null, |
| 46 isModifiable: false); | 47 isModifiable: false); |
| 47 | 48 |
| 48 Scope.nested(Scope parent, {bool isModifiable: true}) | 49 Scope.nested(Scope parent, {bool isModifiable: true}) |
| 49 : this(<String, Builder>{}, null, parent, isModifiable: isModifiable); | 50 : this(<String, Builder>{}, null, parent, isModifiable: isModifiable); |
| 50 | 51 |
| 51 /// Don't use this. Use [becomePartOf] instead. | 52 /// Don't use this. Use [becomePartOf] instead. |
| 52 void set local(_) => internalError("Unsupported operation."); | 53 void set local(_) => deprecated_internalProblem("Unsupported operation."); |
| 53 | 54 |
| 54 /// Don't use this. Use [becomePartOf] instead. | 55 /// Don't use this. Use [becomePartOf] instead. |
| 55 void set setters(_) => internalError("Unsupported operation."); | 56 void set setters(_) => deprecated_internalProblem("Unsupported operation."); |
| 56 | 57 |
| 57 /// Don't use this. Use [becomePartOf] instead. | 58 /// Don't use this. Use [becomePartOf] instead. |
| 58 void set parent(_) => internalError("Unsupported operation."); | 59 void set parent(_) => deprecated_internalProblem("Unsupported operation."); |
| 59 | 60 |
| 60 /// This scope becomes equivalent to [scope]. This is used for parts to | 61 /// This scope becomes equivalent to [scope]. This is used for parts to |
| 61 /// become part of their library's scope. | 62 /// become part of their library's scope. |
| 62 void becomePartOf(Scope scope) { | 63 void becomePartOf(Scope scope) { |
| 63 assert(parent.parent == null); | 64 assert(parent.parent == null); |
| 64 assert(scope.parent.parent == null); | 65 assert(scope.parent.parent == null); |
| 65 super.local = scope.local; | 66 super.local = scope.local; |
| 66 super.setters = scope.setters; | 67 super.setters = scope.setters; |
| 67 super.parent = scope.parent; | 68 super.parent = scope.parent; |
| 68 } | 69 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 113 } |
| 113 | 114 |
| 114 Builder lookup(String name, int charOffset, Uri fileUri, | 115 Builder lookup(String name, int charOffset, Uri fileUri, |
| 115 {bool isInstanceScope: true}) { | 116 {bool isInstanceScope: true}) { |
| 116 recordUse(name, charOffset, fileUri); | 117 recordUse(name, charOffset, fileUri); |
| 117 Builder builder = | 118 Builder builder = |
| 118 lookupIn(name, charOffset, fileUri, local, isInstanceScope); | 119 lookupIn(name, charOffset, fileUri, local, isInstanceScope); |
| 119 if (builder != null) return builder; | 120 if (builder != null) return builder; |
| 120 builder = lookupIn(name, charOffset, fileUri, setters, isInstanceScope); | 121 builder = lookupIn(name, charOffset, fileUri, setters, isInstanceScope); |
| 121 if (builder != null && !builder.hasProblem) { | 122 if (builder != null && !builder.hasProblem) { |
| 122 return new AccessErrorBuilder(name, builder, charOffset, fileUri); | 123 return new deprecated_AccessErrorBuilder( |
| 124 name, builder, charOffset, fileUri); |
| 123 } | 125 } |
| 124 if (!isInstanceScope) { | 126 if (!isInstanceScope) { |
| 125 // For static lookup, do not seach the parent scope. | 127 // For static lookup, do not seach the parent scope. |
| 126 return builder; | 128 return builder; |
| 127 } | 129 } |
| 128 return builder ?? parent?.lookup(name, charOffset, fileUri); | 130 return builder ?? parent?.lookup(name, charOffset, fileUri); |
| 129 } | 131 } |
| 130 | 132 |
| 131 Builder lookupSetter(String name, int charOffset, Uri fileUri, | 133 Builder lookupSetter(String name, int charOffset, Uri fileUri, |
| 132 {bool isInstanceScope: true}) { | 134 {bool isInstanceScope: true}) { |
| 133 recordUse(name, charOffset, fileUri); | 135 recordUse(name, charOffset, fileUri); |
| 134 Builder builder = | 136 Builder builder = |
| 135 lookupIn(name, charOffset, fileUri, setters, isInstanceScope); | 137 lookupIn(name, charOffset, fileUri, setters, isInstanceScope); |
| 136 if (builder != null) return builder; | 138 if (builder != null) return builder; |
| 137 builder = lookupIn(name, charOffset, fileUri, local, isInstanceScope); | 139 builder = lookupIn(name, charOffset, fileUri, local, isInstanceScope); |
| 138 if (builder != null && !builder.hasProblem) { | 140 if (builder != null && !builder.hasProblem) { |
| 139 return new AccessErrorBuilder(name, builder, charOffset, fileUri); | 141 return new deprecated_AccessErrorBuilder( |
| 142 name, builder, charOffset, fileUri); |
| 140 } | 143 } |
| 141 if (!isInstanceScope) { | 144 if (!isInstanceScope) { |
| 142 // For static lookup, do not seach the parent scope. | 145 // For static lookup, do not seach the parent scope. |
| 143 return builder; | 146 return builder; |
| 144 } | 147 } |
| 145 return builder ?? parent?.lookupSetter(name, charOffset, fileUri); | 148 return builder ?? parent?.lookupSetter(name, charOffset, fileUri); |
| 146 } | 149 } |
| 147 | 150 |
| 148 bool hasLocalLabel(String name) => labels != null && labels.containsKey(name); | 151 bool hasLocalLabel(String name) => labels != null && labels.containsKey(name); |
| 149 | 152 |
| 150 void declareLabel(String name, Builder target) { | 153 void declareLabel(String name, Builder target) { |
| 151 if (isModifiable) { | 154 if (isModifiable) { |
| 152 labels ??= <String, Builder>{}; | 155 labels ??= <String, Builder>{}; |
| 153 labels[name] = target; | 156 labels[name] = target; |
| 154 } else { | 157 } else { |
| 155 internalError("Can't extend an unmodifiable scope."); | 158 deprecated_internalProblem("Can't extend an unmodifiable scope."); |
| 156 } | 159 } |
| 157 } | 160 } |
| 158 | 161 |
| 159 void forwardDeclareLabel(String name, Builder target) { | 162 void forwardDeclareLabel(String name, Builder target) { |
| 160 declareLabel(name, target); | 163 declareLabel(name, target); |
| 161 forwardDeclaredLabels ??= <String, Builder>{}; | 164 forwardDeclaredLabels ??= <String, Builder>{}; |
| 162 forwardDeclaredLabels[name] = target; | 165 forwardDeclaredLabels[name] = target; |
| 163 } | 166 } |
| 164 | 167 |
| 165 void claimLabel(String name) { | 168 void claimLabel(String name) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 176 | 179 |
| 177 Builder lookupLabel(String name) { | 180 Builder lookupLabel(String name) { |
| 178 return (labels == null ? null : labels[name]) ?? parent?.lookupLabel(name); | 181 return (labels == null ? null : labels[name]) ?? parent?.lookupLabel(name); |
| 179 } | 182 } |
| 180 | 183 |
| 181 /// Declares that the meaning of [name] in this scope is [builder]. | 184 /// Declares that the meaning of [name] in this scope is [builder]. |
| 182 /// | 185 /// |
| 183 /// If name was used previously in this scope, this method returns an error | 186 /// If name was used previously in this scope, this method returns an error |
| 184 /// that should be reported as a compile-time error. The position of this | 187 /// that should be reported as a compile-time error. The position of this |
| 185 /// error is given by [charOffset] and [fileUri]. | 188 /// error is given by [charOffset] and [fileUri]. |
| 186 InputError declare( | 189 deprecated_InputError declare( |
| 187 String name, Builder builder, int charOffset, Uri fileUri) { | 190 String name, Builder builder, int charOffset, Uri fileUri) { |
| 188 if (isModifiable) { | 191 if (isModifiable) { |
| 189 if (usedNames?.containsKey(name) ?? false) { | 192 if (usedNames?.containsKey(name) ?? false) { |
| 190 return new InputError( | 193 return new deprecated_InputError( |
| 191 fileUri, usedNames[name], "Previous use of '$name'."); | 194 fileUri, usedNames[name], "Previous use of '$name'."); |
| 192 } | 195 } |
| 193 recordUse(name, charOffset, fileUri); | 196 recordUse(name, charOffset, fileUri); |
| 194 local[name] = builder; | 197 local[name] = builder; |
| 195 } else { | 198 } else { |
| 196 internalError("Can't extend an unmodifiable scope."); | 199 deprecated_internalProblem("Can't extend an unmodifiable scope."); |
| 197 } | 200 } |
| 198 return null; | 201 return null; |
| 199 } | 202 } |
| 200 | 203 |
| 201 void merge(Scope scope, | 204 void merge(Scope scope, |
| 202 buildAmbiguousBuilder(String name, Builder existing, Builder member)) { | 205 buildAmbiguousBuilder(String name, Builder existing, Builder member)) { |
| 203 Map<String, Builder> map = local; | 206 Map<String, Builder> map = local; |
| 204 | 207 |
| 205 void mergeMember(String name, Builder member) { | 208 void mergeMember(String name, Builder member) { |
| 206 Builder existing = map[name]; | 209 Builder existing = map[name]; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 269 |
| 267 final Builder builder; | 270 final Builder builder; |
| 268 | 271 |
| 269 ProblemBuilder(this.name, this.builder, int charOffset, Uri fileUri) | 272 ProblemBuilder(this.name, this.builder, int charOffset, Uri fileUri) |
| 270 : super(null, charOffset, fileUri); | 273 : super(null, charOffset, fileUri); |
| 271 | 274 |
| 272 get target => null; | 275 get target => null; |
| 273 | 276 |
| 274 bool get hasProblem => true; | 277 bool get hasProblem => true; |
| 275 | 278 |
| 276 String get message; | 279 String get deprecated_message; |
| 277 | 280 |
| 278 @override | 281 @override |
| 279 String get fullNameForErrors => name; | 282 String get fullNameForErrors => name; |
| 280 } | 283 } |
| 281 | 284 |
| 282 /// Represents a [builder] that's being accessed incorrectly. For example, an | 285 /// Represents a [builder] that's being accessed incorrectly. For example, an |
| 283 /// attempt to write to a final field, or to read from a setter. | 286 /// attempt to write to a final field, or to read from a setter. |
| 284 class AccessErrorBuilder extends ProblemBuilder { | 287 class deprecated_AccessErrorBuilder extends ProblemBuilder { |
| 285 AccessErrorBuilder(String name, Builder builder, int charOffset, Uri fileUri) | 288 deprecated_AccessErrorBuilder( |
| 289 String name, Builder builder, int charOffset, Uri fileUri) |
| 286 : super(name, builder, charOffset, fileUri); | 290 : super(name, builder, charOffset, fileUri); |
| 287 | 291 |
| 288 Builder get parent => builder; | 292 Builder get parent => builder; |
| 289 | 293 |
| 290 bool get isFinal => builder.isFinal; | 294 bool get isFinal => builder.isFinal; |
| 291 | 295 |
| 292 bool get isField => builder.isField; | 296 bool get isField => builder.isField; |
| 293 | 297 |
| 294 bool get isRegularMethod => builder.isRegularMethod; | 298 bool get isRegularMethod => builder.isRegularMethod; |
| 295 | 299 |
| 296 bool get isGetter => !builder.isGetter; | 300 bool get isGetter => !builder.isGetter; |
| 297 | 301 |
| 298 bool get isSetter => !builder.isSetter; | 302 bool get isSetter => !builder.isSetter; |
| 299 | 303 |
| 300 bool get isInstanceMember => builder.isInstanceMember; | 304 bool get isInstanceMember => builder.isInstanceMember; |
| 301 | 305 |
| 302 bool get isStatic => builder.isStatic; | 306 bool get isStatic => builder.isStatic; |
| 303 | 307 |
| 304 bool get isTopLevel => builder.isTopLevel; | 308 bool get isTopLevel => builder.isTopLevel; |
| 305 | 309 |
| 306 bool get isTypeDeclaration => builder.isTypeDeclaration; | 310 bool get isTypeDeclaration => builder.isTypeDeclaration; |
| 307 | 311 |
| 308 bool get isLocal => builder.isLocal; | 312 bool get isLocal => builder.isLocal; |
| 309 | 313 |
| 310 String get message => "Access error: '$name'."; | 314 String get deprecated_message => "Access error: '$name'."; |
| 311 } | 315 } |
| 312 | 316 |
| 313 class AmbiguousBuilder extends ProblemBuilder { | 317 class AmbiguousBuilder extends ProblemBuilder { |
| 314 AmbiguousBuilder(String name, Builder builder, int charOffset, Uri fileUri) | 318 AmbiguousBuilder(String name, Builder builder, int charOffset, Uri fileUri) |
| 315 : super(name, builder, charOffset, fileUri); | 319 : super(name, builder, charOffset, fileUri); |
| 316 | 320 |
| 317 String get message => "Duplicated named: '$name'."; | 321 String get deprecated_message => "Duplicated named: '$name'."; |
| 318 } | 322 } |
| OLD | NEW |