Chromium Code Reviews| 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). |
| 11 class IdentifierContext { | 11 class IdentifierContext { |
| 12 /// Identifier is being declared as the name of an import prefix (i.e. `Foo` | 12 /// Identifier is being declared as the name of an import prefix (i.e. `Foo` |
| 13 /// in `import "..." as Foo;`) | 13 /// in `import "..." as Foo;`) |
| 14 static const importPrefixDeclaration = | 14 static const importPrefixDeclaration = |
| 15 const IdentifierContext._('importPrefixDeclaration'); | 15 const IdentifierContext._('importPrefixDeclaration', inDeclaration: true); |
| 16 | 16 |
| 17 /// Identifier is the start of a dotted name in a conditional import or | 17 /// Identifier is the start of a dotted name in a conditional import or |
| 18 /// export. | 18 /// export. |
| 19 static const dottedName = const IdentifierContext._('dottedName'); | 19 static const dottedName = const IdentifierContext._('dottedName'); |
| 20 | 20 |
| 21 /// Identifier is part of a dotted name in a conditional import or export, but | 21 /// Identifier is part of a dotted name in a conditional import or export, but |
| 22 /// it's not the first identifier of the dotted name. | 22 /// it's not the first identifier of the dotted name. |
| 23 static const dottedNameContinuation = | 23 static const dottedNameContinuation = |
| 24 const IdentifierContext._('dottedNameContinuation', isContinuation: true); | 24 const IdentifierContext._('dottedNameContinuation', isContinuation: true); |
| 25 | 25 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 38 const IdentifierContext._('metadataContinuation', isContinuation: true); | 38 const IdentifierContext._('metadataContinuation', isContinuation: true); |
| 39 | 39 |
| 40 /// Identifier is part of a name in an annotation that precedes a declaration, | 40 /// Identifier is part of a name in an annotation that precedes a declaration, |
| 41 /// but it appears after type parameters (e.g. `foo` in `@X<Y>.foo()`). | 41 /// but it appears after type parameters (e.g. `foo` in `@X<Y>.foo()`). |
| 42 static const metadataContinuationAfterTypeArguments = | 42 static const metadataContinuationAfterTypeArguments = |
| 43 const IdentifierContext._('metadataContinuationAfterTypeArguments', | 43 const IdentifierContext._('metadataContinuationAfterTypeArguments', |
| 44 isContinuation: true); | 44 isContinuation: true); |
| 45 | 45 |
| 46 /// Identifier is the name being declared by a typedef declaration. | 46 /// Identifier is the name being declared by a typedef declaration. |
| 47 static const typedefDeclaration = | 47 static const typedefDeclaration = |
| 48 const IdentifierContext._('typedefDeclaration'); | 48 const IdentifierContext._('typedefDeclaration', inDeclaration: true); |
| 49 | 49 |
| 50 /// Identifier is a field initializer in a formal parameter list (i.e. it | 50 /// Identifier is a field initializer in a formal parameter list (i.e. it |
| 51 /// appears directly after `this.`). | 51 /// appears directly after `this.`). |
| 52 static const fieldInitializer = | 52 static const fieldInitializer = |
| 53 const IdentifierContext._('fieldInitializer', isContinuation: true); | 53 const IdentifierContext._('fieldInitializer', isContinuation: true); |
| 54 | 54 |
| 55 /// Identifier is a formal parameter being declared as part of a function, | 55 /// Identifier is a formal parameter being declared as part of a function, |
| 56 /// method, or typedef declaration. | 56 /// method, or typedef declaration. |
| 57 static const formalParameterDeclaration = | 57 static const formalParameterDeclaration = const IdentifierContext._( |
| 58 const IdentifierContext._('formalParameterDeclaration'); | 58 'formalParameterDeclaration', |
| 59 inDeclaration: true); | |
| 59 | 60 |
| 60 /// Identifier is the start of a library name (e.g. `foo` in the directive | 61 /// Identifier is the start of a library name (e.g. `foo` in the directive |
| 61 /// 'library foo;`). | 62 /// 'library foo;`). |
| 62 static const libraryName = const IdentifierContext._('libraryName', | 63 static const libraryName = const IdentifierContext._('libraryName', |
| 63 inLibraryOrPartOfDeclaration: true); | 64 inLibraryOrPartOfDeclaration: true); |
| 64 | 65 |
| 65 /// Identifier is part of a library name, but it's not the first identifier in | 66 /// Identifier is part of a library name, but it's not the first identifier in |
| 66 /// the name. | 67 /// the name. |
| 67 static const libraryNameContinuation = const IdentifierContext._( | 68 static const libraryNameContinuation = const IdentifierContext._( |
| 68 'libraryNameContinuation', | 69 'libraryNameContinuation', |
| 69 inLibraryOrPartOfDeclaration: true, | 70 inLibraryOrPartOfDeclaration: true, |
| 70 isContinuation: true); | 71 isContinuation: true); |
| 71 | 72 |
| 72 /// Identifier is the start of a library name referenced by a `part of` | 73 /// Identifier is the start of a library name referenced by a `part of` |
| 73 /// directive (e.g. `foo` in the directive `part of foo;`). | 74 /// directive (e.g. `foo` in the directive `part of foo;`). |
| 74 static const partName = | 75 static const partName = |
| 75 const IdentifierContext._('partName', inLibraryOrPartOfDeclaration: true); | 76 const IdentifierContext._('partName', inLibraryOrPartOfDeclaration: true); |
| 76 | 77 |
| 77 /// Identifier is part of a library name referenced by a `part of` directive, | 78 /// Identifier is part of a library name referenced by a `part of` directive, |
| 78 /// but it's not the first identifier in the name. | 79 /// but it's not the first identifier in the name. |
| 79 static const partNameContinuation = const IdentifierContext._( | 80 static const partNameContinuation = const IdentifierContext._( |
| 80 'partNameContinuation', | 81 'partNameContinuation', |
| 81 inLibraryOrPartOfDeclaration: true, | 82 inLibraryOrPartOfDeclaration: true, |
| 82 isContinuation: true); | 83 isContinuation: true); |
| 83 | 84 |
| 84 /// Identifier is the type name being declared by an enum declaration. | 85 /// Identifier is the type name being declared by an enum declaration. |
| 85 static const enumDeclaration = const IdentifierContext._('enumDeclaration'); | 86 static const enumDeclaration = |
| 87 const IdentifierContext._('enumDeclaration', inDeclaration: true); | |
| 86 | 88 |
| 87 /// Identifier is an enumerated value name being declared by an enum | 89 /// Identifier is an enumerated value name being declared by an enum |
| 88 /// declaration. | 90 /// declaration. |
| 89 static const enumValueDeclaration = | 91 static const enumValueDeclaration = |
| 90 const IdentifierContext._('enumValueDeclaration'); | 92 const IdentifierContext._('enumValueDeclaration', inDeclaration: true); |
| 91 | 93 |
| 92 /// Identifier is the name being declared by a named mixin declaration (e.g. | 94 /// Identifier is the name being declared by a named mixin declaration (e.g. |
| 93 /// `Foo` in `class Foo = X with Y;`). | 95 /// `Foo` in `class Foo = X with Y;`). |
| 94 static const namedMixinDeclaration = | 96 static const namedMixinDeclaration = |
| 95 const IdentifierContext._('namedMixinDeclaration'); | 97 const IdentifierContext._('namedMixinDeclaration', inDeclaration: true); |
| 96 | 98 |
| 97 /// Identifier is the name being declared by a class declaration. | 99 /// Identifier is the name being declared by a class declaration. |
| 98 static const classDeclaration = const IdentifierContext._('classDeclaration'); | 100 static const classDeclaration = |
| 101 const IdentifierContext._('classDeclaration', inDeclaration: true); | |
| 99 | 102 |
| 100 /// Identifier is the name of a type variable being declared (e.g. `Foo` in | 103 /// Identifier is the name of a type variable being declared (e.g. `Foo` in |
| 101 /// `class C<Foo extends num> {}`). | 104 /// `class C<Foo extends num> {}`). |
| 102 static const typeVariableDeclaration = | 105 static const typeVariableDeclaration = |
| 103 const IdentifierContext._('typeVariableDeclaration'); | 106 const IdentifierContext._('typeVariableDeclaration', inDeclaration: true); |
| 104 | 107 |
| 105 /// Identifier is the start of a reference to a type declared elsewhere. | 108 /// Identifier is the start of a reference to a type declared elsewhere. |
| 106 static const typeReference = | 109 static const typeReference = |
| 107 const IdentifierContext._('typeReference', isScopeReference: true); | 110 const IdentifierContext._('typeReference', isScopeReference: true); |
| 108 | 111 |
| 109 /// Identifier is part of a reference to a type declared elsewhere, but it's | 112 /// Identifier is part of a reference to a type declared elsewhere, but it's |
| 110 /// not the first identifier of the reference. | 113 /// not the first identifier of the reference. |
| 111 static const typeReferenceContinuation = const IdentifierContext._( | 114 static const typeReferenceContinuation = const IdentifierContext._( |
| 112 'typeReferenceContinuation', | 115 'typeReferenceContinuation', |
| 113 isContinuation: true); | 116 isContinuation: true); |
| 114 | 117 |
| 115 /// Identifier is a name being declared by a top level variable declaration. | 118 /// Identifier is a name being declared by a top level variable declaration. |
| 116 static const topLevelVariableDeclaration = | 119 static const topLevelVariableDeclaration = const IdentifierContext._( |
| 117 const IdentifierContext._('topLevelVariableDeclaration'); | 120 'topLevelVariableDeclaration', |
| 121 inDeclaration: true); | |
| 118 | 122 |
| 119 /// Identifier is a name being declared by a field declaration. | 123 /// Identifier is a name being declared by a field declaration. |
| 120 static const fieldDeclaration = const IdentifierContext._('fieldDeclaration'); | 124 static const fieldDeclaration = |
| 125 const IdentifierContext._('fieldDeclaration', inDeclaration: true); | |
| 121 | 126 |
| 122 /// Identifier is the name being declared by a top level function declaration. | 127 /// Identifier is the name being declared by a top level function declaration. |
| 123 static const topLevelFunctionDeclaration = | 128 static const topLevelFunctionDeclaration = const IdentifierContext._( |
| 124 const IdentifierContext._('topLevelFunctionDeclaration'); | 129 'topLevelFunctionDeclaration', |
| 130 inDeclaration: true); | |
| 125 | 131 |
| 126 /// Identifier is the start of the name being declared by a method | 132 /// Identifier is the start of the name being declared by a method |
| 127 /// declaration. | 133 /// declaration. |
| 128 static const methodDeclaration = | 134 static const methodDeclaration = |
| 129 const IdentifierContext._('methodDeclaration'); | 135 const IdentifierContext._('methodDeclaration', inDeclaration: true); |
|
Paul Berry
2017/03/13 18:58:14
Are we going to have a bug with constructors, e.g.
scheglov
2017/03/13 19:54:49
You're right, this was a bug for ast_builder.
I ad
| |
| 130 | 136 |
| 131 /// Identifier is part of the name being declared by a method declaration, | 137 /// Identifier is part of the name being declared by a method declaration, |
| 132 /// but it's not the first identifier of the name. | 138 /// but it's not the first identifier of the name. |
| 133 /// | 139 /// |
| 134 /// In valid Dart, this can only happen if the identifier is the name of a | 140 /// In valid Dart, this can only happen if the identifier is the name of a |
| 135 /// named constructor which is being declared, e.g. `foo` in | 141 /// named constructor which is being declared, e.g. `foo` in |
| 136 /// `class C { C.foo(); }`. | 142 /// `class C { C.foo(); }`. |
| 137 static const methodDeclarationContinuation = const IdentifierContext._( | 143 static const methodDeclarationContinuation = const IdentifierContext._( |
| 138 'methodDeclarationContinuation', | 144 'methodDeclarationContinuation', |
| 145 inDeclaration: true, | |
| 139 isContinuation: true); | 146 isContinuation: true); |
| 140 | 147 |
| 141 /// Identifier appears after the word `operator` in a method declaration. | 148 /// Identifier appears after the word `operator` in a method declaration. |
| 142 /// | 149 /// |
| 143 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only | 150 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only |
| 144 /// occur as part of error recovery? If it's only as part of error recovery, | 151 /// occur as part of error recovery? If it's only as part of error recovery, |
| 145 /// perhaps we should just re-use methodDeclaration. | 152 /// perhaps we should just re-use methodDeclaration. |
| 146 static const operatorName = const IdentifierContext._('operatorName'); | 153 static const operatorName = const IdentifierContext._('operatorName'); |
| 147 | 154 |
| 148 /// Identifier is the name being declared by a local function declaration that | 155 /// Identifier is the name being declared by a local function declaration that |
| 149 /// uses a "get" or "set" keyword. | 156 /// uses a "get" or "set" keyword. |
| 150 /// | 157 /// |
| 151 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only | 158 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only |
| 152 /// occur as part of error recovery? If it's only as part of error recovery, | 159 /// occur as part of error recovery? If it's only as part of error recovery, |
| 153 /// perhaps we should just re-use localFunctionDeclaration. | 160 /// perhaps we should just re-use localFunctionDeclaration. |
| 154 static const localAccessorDeclaration = | 161 static const localAccessorDeclaration = const IdentifierContext._( |
| 155 const IdentifierContext._('localAccessorDeclaration'); | 162 'localAccessorDeclaration', |
| 163 inDeclaration: true); | |
| 156 | 164 |
| 157 /// Identifier is the start of the name being declared by a local function | 165 /// Identifier is the start of the name being declared by a local function |
| 158 /// declaration. | 166 /// declaration. |
| 159 static const localFunctionDeclaration = | 167 static const localFunctionDeclaration = const IdentifierContext._( |
| 160 const IdentifierContext._('localFunctionDeclaration'); | 168 'localFunctionDeclaration', |
| 169 inDeclaration: true); | |
| 161 | 170 |
| 162 /// Identifier is part of the name being declared by a local function | 171 /// Identifier is part of the name being declared by a local function |
| 163 /// declaration, but it's not the first identifier of the name. | 172 /// declaration, but it's not the first identifier of the name. |
| 164 /// | 173 /// |
| 165 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only | 174 /// TODO(paulberry,ahe): Does this ever occur in valid Dart, or does it only |
| 166 /// occur as part of error recovery? | 175 /// occur as part of error recovery? |
| 167 static const localFunctionDeclarationContinuation = const IdentifierContext._( | 176 static const localFunctionDeclarationContinuation = const IdentifierContext._( |
| 168 'localFunctionDeclarationContinuation', | 177 'localFunctionDeclarationContinuation', |
| 178 inDeclaration: true, | |
| 169 isContinuation: true); | 179 isContinuation: true); |
| 170 | 180 |
| 171 /// Identifier is the name appearing in a function exrpession. | 181 /// Identifier is the name appearing in a function expression. |
| 172 /// | 182 /// |
| 173 /// TODO(paulberry,ahe): What is an example of valid Dart code where this | 183 /// TODO(paulberry,ahe): What is an example of valid Dart code where this |
| 174 /// would occur? | 184 /// would occur? |
| 175 static const functionExpressionName = | 185 static const functionExpressionName = |
| 176 const IdentifierContext._('functionExpressionName'); | 186 const IdentifierContext._('functionExpressionName'); |
| 177 | 187 |
| 178 /// Identifier is the start of a reference to a constructor declared | 188 /// Identifier is the start of a reference to a constructor declared |
| 179 /// elsewhere. | 189 /// elsewhere. |
| 180 static const constructorReference = | 190 static const constructorReference = |
| 181 const IdentifierContext._('constructorReference', isScopeReference: true); | 191 const IdentifierContext._('constructorReference', isScopeReference: true); |
| 182 | 192 |
| 183 /// Identifier is part of a reference to a constructor declared elsewhere, but | 193 /// Identifier is part of a reference to a constructor declared elsewhere, but |
| 184 /// it's not the first identifier of the reference. | 194 /// it's not the first identifier of the reference. |
| 185 static const constructorReferenceContinuation = const IdentifierContext._( | 195 static const constructorReferenceContinuation = const IdentifierContext._( |
| 186 'constructorReferenceContinuation', | 196 'constructorReferenceContinuation', |
| 187 isContinuation: true); | 197 isContinuation: true); |
| 188 | 198 |
| 189 /// Identifier is part of a reference to a constructor declared elsewhere, but | 199 /// Identifier is part of a reference to a constructor declared elsewhere, but |
| 190 /// it appears after type parameters (e.g. `foo` in `X<Y>.foo`). | 200 /// it appears after type parameters (e.g. `foo` in `X<Y>.foo`). |
| 191 static const constructorReferenceContinuationAfterTypeArguments = | 201 static const constructorReferenceContinuationAfterTypeArguments = |
| 192 const IdentifierContext._( | 202 const IdentifierContext._( |
| 193 'constructorReferenceContinuationAfterTypeArguments', | 203 'constructorReferenceContinuationAfterTypeArguments', |
| 194 isContinuation: true); | 204 isContinuation: true); |
| 195 | 205 |
| 196 /// Identifier is the declaration of a label (i.e. it is followed by `:` and | 206 /// Identifier is the declaration of a label (i.e. it is followed by `:` and |
| 197 /// then a statement). | 207 /// then a statement). |
| 198 static const labelDeclaration = const IdentifierContext._('labelDeclaration'); | 208 static const labelDeclaration = |
| 209 const IdentifierContext._('labelDeclaration', inDeclaration: true); | |
| 199 | 210 |
| 200 /// Identifier is the start of a reference occurring in a literal symbol (e.g. | 211 /// Identifier is the start of a reference occurring in a literal symbol (e.g. |
| 201 /// `foo` in `#foo`). | 212 /// `foo` in `#foo`). |
| 202 static const literalSymbol = | 213 static const literalSymbol = |
| 203 const IdentifierContext._('literalSymbol', inSymbol: true); | 214 const IdentifierContext._('literalSymbol', inSymbol: true); |
| 204 | 215 |
| 205 /// Identifier is part of a reference occurring in a literal symbol, but it's | 216 /// Identifier is part of a reference occurring in a literal symbol, but it's |
| 206 /// not the first identifier of the reference (e.g. `foo` in `#prefix.foo`). | 217 /// not the first identifier of the reference (e.g. `foo` in `#prefix.foo`). |
| 207 static const literalSymbolContinuation = const IdentifierContext._( | 218 static const literalSymbolContinuation = const IdentifierContext._( |
| 208 'literalSymbolContinuation', | 219 'literalSymbolContinuation', |
| 209 inSymbol: true, | 220 inSymbol: true, |
| 210 isContinuation: true); | 221 isContinuation: true); |
| 211 | 222 |
| 212 /// Identifier appears in an expression, and it does not immediately follow a | 223 /// Identifier appears in an expression, and it does not immediately follow a |
| 213 /// `.`. | 224 /// `.`. |
| 214 static const expression = | 225 static const expression = |
| 215 const IdentifierContext._('expression', isScopeReference: true); | 226 const IdentifierContext._('expression', isScopeReference: true); |
| 216 | 227 |
| 217 /// Identifier appears in an expression, and it immediately follows a `.`. | 228 /// Identifier appears in an expression, and it immediately follows a `.`. |
| 218 static const expressionContinuation = | 229 static const expressionContinuation = |
| 219 const IdentifierContext._('expressionContinuation', isContinuation: true); | 230 const IdentifierContext._('expressionContinuation', isContinuation: true); |
| 220 | 231 |
| 221 /// Identifier is a reference to a named argument of a function or method | 232 /// Identifier is a reference to a named argument of a function or method |
| 222 /// invocation (e.g. `foo` in `f(foo: 0);`. | 233 /// invocation (e.g. `foo` in `f(foo: 0);`. |
| 223 static const namedArgumentReference = | 234 static const namedArgumentReference = |
| 224 const IdentifierContext._('namedArgumentReference'); | 235 const IdentifierContext._('namedArgumentReference'); |
| 225 | 236 |
| 226 /// Identifier is a name being declared by a local variable declaration. | 237 /// Identifier is a name being declared by a local variable declaration. |
| 227 static const localVariableDeclaration = | 238 static const localVariableDeclaration = const IdentifierContext._( |
| 228 const IdentifierContext._('localVariableDeclaration'); | 239 'localVariableDeclaration', |
| 240 inDeclaration: true); | |
| 229 | 241 |
| 230 /// Identifier is a reference to a label (e.g. `foo` in `break foo;`). | 242 /// Identifier is a reference to a label (e.g. `foo` in `break foo;`). |
| 231 static const labelReference = | 243 static const labelReference = |
| 232 const IdentifierContext._('labelReference', isScopeReference: true); | 244 const IdentifierContext._('labelReference', isScopeReference: true); |
| 233 | 245 |
| 234 final String _name; | 246 final String _name; |
| 235 | 247 |
| 248 /// Indicates whether the identifier is a name in a declaration. | |
|
Paul Berry
2017/03/13 18:58:14
Suggestion: change this comment to "Indicates whet
scheglov
2017/03/13 19:54:49
Done.
Thanks.
| |
| 249 final bool inDeclaration; | |
| 250 | |
| 236 /// Indicates whether the identifier is within a `library` or `part of` | 251 /// Indicates whether the identifier is within a `library` or `part of` |
| 237 /// declaration. | 252 /// declaration. |
| 238 final bool inLibraryOrPartOfDeclaration; | 253 final bool inLibraryOrPartOfDeclaration; |
| 239 | 254 |
| 240 /// Indicates whether the identifier is within a symbol literal. | 255 /// Indicates whether the identifier is within a symbol literal. |
| 241 final bool inSymbol; | 256 final bool inSymbol; |
| 242 | 257 |
| 243 /// Indicates whether the identifier follows a `.`. | 258 /// Indicates whether the identifier follows a `.`. |
| 244 final bool isContinuation; | 259 final bool isContinuation; |
| 245 | 260 |
| 246 /// Indicates whether the identifier should be looked up in the current scope. | 261 /// Indicates whether the identifier should be looked up in the current scope. |
| 247 final bool isScopeReference; | 262 final bool isScopeReference; |
| 248 | 263 |
| 249 const IdentifierContext._(this._name, | 264 const IdentifierContext._(this._name, |
| 250 {this.inLibraryOrPartOfDeclaration: false, | 265 {this.inDeclaration: false, |
| 266 this.inLibraryOrPartOfDeclaration: false, | |
| 251 this.inSymbol: false, | 267 this.inSymbol: false, |
| 252 this.isContinuation: false, | 268 this.isContinuation: false, |
| 253 this.isScopeReference: false}); | 269 this.isScopeReference: false}); |
| 254 | 270 |
| 255 String toString() => _name; | 271 String toString() => _name; |
| 256 } | 272 } |
| OLD | NEW |