| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /// Information about the parser state which is passed to the listener at the | 5 /// Information about the parser state which is passed to the listener at the |
| 6 /// time an identifier is encountered. | 6 /// time an identifier is encountered. |
| 7 /// | 7 /// |
| 8 /// This can be used by the listener to determine the context in which the | 8 /// This can be used by the listener to determine the context in which the |
| 9 /// identifier appears; that in turn can help the listener decide how to resolve | 9 /// identifier appears; that in turn can help the listener decide how to resolve |
| 10 /// the identifier (if the listener is doing resolution). | 10 /// the identifier (if the listener is doing resolution). |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 /// `.`. | 233 /// `.`. |
| 234 static const expression = | 234 static const expression = |
| 235 const IdentifierContext._('expression', isScopeReference: true); | 235 const IdentifierContext._('expression', isScopeReference: true); |
| 236 | 236 |
| 237 /// Identifier appears in an expression, and it immediately follows a `.`. | 237 /// Identifier appears in an expression, and it immediately follows a `.`. |
| 238 static const expressionContinuation = | 238 static const expressionContinuation = |
| 239 const IdentifierContext._('expressionContinuation', isContinuation: true); | 239 const IdentifierContext._('expressionContinuation', isContinuation: true); |
| 240 | 240 |
| 241 /// Identifier is a reference to a named argument of a function or method | 241 /// Identifier is a reference to a named argument of a function or method |
| 242 /// invocation (e.g. `foo` in `f(foo: 0);`. | 242 /// invocation (e.g. `foo` in `f(foo: 0);`. |
| 243 static const namedArgumentReference = | 243 static const namedArgumentReference = const IdentifierContext._( |
| 244 const IdentifierContext._('namedArgumentReference'); | 244 'namedArgumentReference', |
| 245 allowedInConstantExpression: true); |
| 245 | 246 |
| 246 /// Identifier is a name being declared by a local variable declaration. | 247 /// Identifier is a name being declared by a local variable declaration. |
| 247 static const localVariableDeclaration = const IdentifierContext._( | 248 static const localVariableDeclaration = const IdentifierContext._( |
| 248 'localVariableDeclaration', | 249 'localVariableDeclaration', |
| 249 inDeclaration: true); | 250 inDeclaration: true); |
| 250 | 251 |
| 251 /// Identifier is a reference to a label (e.g. `foo` in `break foo;`). | 252 /// Identifier is a reference to a label (e.g. `foo` in `break foo;`). |
| 252 /// Labels have their own scope. | 253 /// Labels have their own scope. |
| 253 static const labelReference = const IdentifierContext._('labelReference'); | 254 static const labelReference = const IdentifierContext._('labelReference'); |
| 254 | 255 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 267 | 268 |
| 268 /// Indicates whether the identifier follows a `.`. | 269 /// Indicates whether the identifier follows a `.`. |
| 269 final bool isContinuation; | 270 final bool isContinuation; |
| 270 | 271 |
| 271 /// Indicates whether the identifier should be looked up in the current scope. | 272 /// Indicates whether the identifier should be looked up in the current scope. |
| 272 final bool isScopeReference; | 273 final bool isScopeReference; |
| 273 | 274 |
| 274 /// Indicates whether built-in identifiers are allowed in this context. | 275 /// Indicates whether built-in identifiers are allowed in this context. |
| 275 final bool isBuiltInIdentifierAllowed; | 276 final bool isBuiltInIdentifierAllowed; |
| 276 | 277 |
| 278 /// Indicated whether the identifier is allowed in a context where constant |
| 279 /// expressions are required. |
| 280 final bool allowedInConstantExpression; |
| 281 |
| 277 const IdentifierContext._(this._name, | 282 const IdentifierContext._(this._name, |
| 278 {this.inDeclaration: false, | 283 {this.inDeclaration: false, |
| 279 this.inLibraryOrPartOfDeclaration: false, | 284 this.inLibraryOrPartOfDeclaration: false, |
| 280 this.inSymbol: false, | 285 this.inSymbol: false, |
| 281 this.isContinuation: false, | 286 this.isContinuation: false, |
| 282 this.isScopeReference: false, | 287 this.isScopeReference: false, |
| 283 this.isBuiltInIdentifierAllowed: true}); | 288 this.isBuiltInIdentifierAllowed: true, |
| 289 bool allowedInConstantExpression}) |
| 290 : this.allowedInConstantExpression = |
| 291 // Generally, declarations are legal in constant expressions. A |
| 292 // continuation doesn't affect constant expressions: if what it's |
| 293 // continuing is a problem, it has already been reported. |
| 294 allowedInConstantExpression ?? (inDeclaration || isContinuation); |
| 284 | 295 |
| 285 String toString() => _name; | 296 String toString() => _name; |
| 286 } | 297 } |
| OLD | NEW |