Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: pkg/analyzer2dart/lib/src/identifier_semantics.dart

Issue 914613002: Revert "Add sharedfrontend package" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /** 5 /**
6 * Code for classifying the semantics of identifiers appearing in a Dart file. 6 * Code for classifying the semantics of identifiers appearing in a Dart file.
7 */ 7 */
8 library analyzer2dart.identifierSemantics; 8 library analyzer2dart.identifierSemantics;
9 9
10 import 'package:analyzer/analyzer.dart'; 10 import 'package:analyzer/analyzer.dart';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:sharedfrontend/elements.dart' as shared;
13 import 'package:sharedfrontend/src/access_semantics.dart';
14
15 12
16 // TODO(johnniwinther,paulberry): This should be a constant. 13 // TODO(johnniwinther,paulberry): This should be a constant.
17 final AccessSemanticsVisitor ACCESS_SEMANTICS_VISITOR = 14 final AccessSemanticsVisitor ACCESS_SEMANTICS_VISITOR =
18 new AccessSemanticsVisitor(); 15 new AccessSemanticsVisitor();
19 16
17 /**
18 * Enum representing the different kinds of destinations which a property
19 * access or method or function invocation might refer to.
20 */
21 class AccessKind {
22 /**
23 * The destination of the access is an instance method, property, or field
24 * of a class, and thus must be determined dynamically.
25 */
26 static const AccessKind DYNAMIC = const AccessKind._('DYNAMIC');
27
28 /**
29 * The destination of the access is a function that is defined locally within
30 * an enclosing function or method.
31 */
32 static const AccessKind LOCAL_FUNCTION = const AccessKind._('LOCAL_FUNCTION');
33
34 /**
35 * The destination of the access is a variable that is defined locally within
36 * an enclosing function or method.
37 */
38 static const AccessKind LOCAL_VARIABLE = const AccessKind._('LOCAL_VARIABLE');
39
40 /**
41 * The destination of the access is a variable that is defined as a parameter
42 * to an enclosing function or method.
43 */
44 static const AccessKind PARAMETER = const AccessKind._('PARAMETER');
45
46 /**
47 * The destination of the access is a field that is defined statically within
48 * a class, or a top level variable within a library.
49 */
50 static const AccessKind STATIC_FIELD = const AccessKind._('STATIC_FIELD');
51
52 /**
53 * The destination of the access is a method that is defined statically
54 * within a class, or at top level within a library.
55 */
56 static const AccessKind STATIC_METHOD = const AccessKind._('STATIC_METHOD');
57
58 /**
59 * The destination of the access is a property getter/setter that is defined
60 * statically within a class, or at top level within a library.
61 */
62 static const AccessKind STATIC_PROPERTY =
63 const AccessKind._('STATIC_PROPERTY');
64
65 /**
66 * The destination of the access is a toplevel class, function typedef, mixin
67 * application, or the built-in type "dynamic".
68 */
69 static const AccessKind TOPLEVEL_TYPE = const AccessKind._('TOPLEVEL_TYPE');
70
71 /**
72 * The destination of the access is a type parameter of the enclosing class.
73 */
74 static const AccessKind TYPE_PARAMETER = const AccessKind._('TYPE_PARAMETER');
75
76 final String name;
77
78 const AccessKind._(this.name);
79
80 String toString() => name;
81 }
82
83 /**
84 * Data structure used to classify the semantics of a property access or method
85 * or function invocation.
86 */
87 // TODO(paulberry,johnniwinther): Support index operations in AccessSemantics.
88 class AccessSemantics {
89 /**
90 * The kind of access.
91 */
92 final AccessKind kind;
93
94 /**
95 * The identifier being used to access the property, method, or function.
96 */
97 final SimpleIdentifier identifier;
98
99 /**
100 * The element being accessed, if statically known. This will be null if
101 * [kind] is DYNAMIC or if the element is undefined (e.g. an attempt to
102 * access a non-existent static method in a class).
103 */
104 final Element element;
105
106 /**
107 * The class containing the element being accessed, if this is a static
108 * reference to an element in a class. This will be null if [kind] is
109 * DYNAMIC, LOCAL_FUNCTION, LOCAL_VARIABLE, PARAMETER, TOPLEVEL_CLASS, or
110 * TYPE_PARAMETER, or if the element being accessed is defined at toplevel
111 * within a library.
112 *
113 * Note: it is possible for [classElement] to be non-null and for [element]
114 * to be null; for example this occurs if the element being accessed is a
115 * non-existent static method or field inside an existing class.
116 */
117 final ClassElement classElement;
118
119 // TODO(paulberry): would it also be useful to store the libraryElement?
120
121 /**
122 * When [kind] is DYNAMIC, the expression whose runtime type determines the
123 * class in which [identifier] should be looked up. Null if the expression
124 * is implicit "this".
125 *
126 * When [kind] is not DYNAMIC, this field is always null.
127 */
128 final Expression target;
129
130 /**
131 * True if this is an invocation of a method, or a call on a property.
132 */
133 final bool isInvoke;
134
135 AccessSemantics.dynamic(this.identifier, this.target, {this.isInvoke: false})
136 : kind = AccessKind.DYNAMIC,
137 element = null,
138 classElement = null;
139
140 AccessSemantics.localFunction(this.identifier, this.element, {this.isInvoke:
141 false})
142 : kind = AccessKind.LOCAL_FUNCTION,
143 classElement = null,
144 target = null;
145
146 AccessSemantics.localVariable(this.identifier, this.element, {this.isInvoke:
147 false})
148 : kind = AccessKind.LOCAL_VARIABLE,
149 classElement = null,
150 target = null;
151
152 AccessSemantics.parameter(this.identifier, this.element, {this.isInvoke:
153 false})
154 : kind = AccessKind.PARAMETER,
155 classElement = null,
156 target = null;
157
158 AccessSemantics.staticField(this.identifier, this.element, this.classElement,
159 {this.isInvoke: false})
160 : kind = AccessKind.STATIC_FIELD,
161 target = null;
162
163 AccessSemantics.staticMethod(this.identifier, this.element, this.classElement,
164 {this.isInvoke: false})
165 : kind = AccessKind.STATIC_METHOD,
166 target = null;
167
168 AccessSemantics.staticProperty(this.identifier, this.element,
169 this.classElement, {this.isInvoke: false})
170 : kind = AccessKind.STATIC_PROPERTY,
171 target = null;
172
173 AccessSemantics.toplevelType(this.identifier, this.element, {this.isInvoke:
174 false})
175 : kind = AccessKind.TOPLEVEL_TYPE,
176 classElement = null,
177 target = null;
178
179 AccessSemantics.typeParameter(this.identifier, this.element, {this.isInvoke:
180 false})
181 : kind = AccessKind.TYPE_PARAMETER,
182 classElement = null,
183 target = null;
184
185 /**
186 * True if this is a read access to a property, or a method tear-off. Note
187 * that both [isRead] and [isWrite] will be true in the case of a
188 * read-modify-write operation (e.g. "+=").
189 */
190 bool get isRead => !isInvoke && identifier.inGetterContext();
191
192 /**
193 * True if this is a write access to a property, or an (erroneous) attempt to
194 * write to a method. Note that both [isRead] and [isWrite] will be true in
195 * the case of a read-modify-write operation (e.g. "+=").
196 */
197 bool get isWrite => identifier.inSetterContext();
198
199 String toString() {
200 StringBuffer sb = new StringBuffer();
201 sb.write('AccessSemantics[');
202 sb.write('kind=$kind,');
203 if (isRead && isWrite) {
204 assert(!isInvoke);
205 sb.write('read/write,');
206 } else if (isRead) {
207 sb.write('read,');
208 } else if (isWrite) {
209 sb.write('write,');
210 } else if (isInvoke) {
211 sb.write('call,');
212 }
213 if (element != null) {
214 sb.write('element=');
215 if (classElement != null) {
216 sb.write('${classElement.name}.');
217 }
218 sb.write('${element}');
219 } else {
220 if (target == null) {
221 sb.write('target=this.$identifier');
222 } else {
223 sb.write('target=$target.$identifier');
224 }
225 }
226 sb.write(']');
227 return sb.toString();
228 }
229 }
230
20 // TODO(johnniwinther,paulberry): This should extend a non-recursive visitor. 231 // TODO(johnniwinther,paulberry): This should extend a non-recursive visitor.
21 class AccessSemanticsVisitor extends RecursiveAstVisitor<AccessSemantics> { 232 class AccessSemanticsVisitor extends RecursiveAstVisitor<AccessSemantics> {
22 /** 233 /**
23 * Return the semantics for [node]. 234 * Return the semantics for [node].
24 */ 235 */
25 @override 236 @override
26 AccessSemantics visitMethodInvocation(MethodInvocation node) { 237 AccessSemantics visitMethodInvocation(MethodInvocation node) {
27 Expression target = node.realTarget; 238 Expression target = node.realTarget;
28 Element staticElement = node.methodName.staticElement; 239 Element staticElement = node.methodName.staticElement;
29 if (target == null) { 240 if (target == null) {
30 if (staticElement is FunctionElement) { 241 if (staticElement is FunctionElement) {
31 if (staticElement.enclosingElement is CompilationUnitElement) { 242 if (staticElement.enclosingElement is CompilationUnitElement) {
32 return new AccessSemantics.staticMethod( 243 return new AccessSemantics.staticMethod(
33 node.methodName.name, 244 node.methodName,
34 staticElement, 245 staticElement,
35 null, 246 null,
36 isInvoke: true); 247 isInvoke: true);
37 } else { 248 } else {
38 return new AccessSemantics.localFunction( 249 return new AccessSemantics.localFunction(
39 node.methodName.name, 250 node.methodName,
40 staticElement, 251 staticElement,
41 isInvoke: true); 252 isInvoke: true);
42 } 253 }
43 } else if (staticElement is MethodElement && staticElement.isStatic) { 254 } else if (staticElement is MethodElement && staticElement.isStatic) {
44 return new AccessSemantics.staticMethod( 255 return new AccessSemantics.staticMethod(
45 node.methodName.name, 256 node.methodName,
46 staticElement, 257 staticElement,
47 staticElement.enclosingElement, 258 staticElement.enclosingElement,
48 isInvoke: true); 259 isInvoke: true);
49 } else if (staticElement is PropertyAccessorElement) { 260 } else if (staticElement is PropertyAccessorElement) {
50 if (staticElement.isSynthetic) { 261 if (staticElement.isSynthetic) {
51 if (staticElement.enclosingElement is CompilationUnitElement) { 262 if (staticElement.enclosingElement is CompilationUnitElement) {
52 return new AccessSemantics.staticField( 263 return new AccessSemantics.staticField(
53 node.methodName.name, 264 node.methodName,
54 staticElement.variable, 265 staticElement.variable,
55 null, 266 null,
56 isInvoke: true); 267 isInvoke: true);
57 } else if (staticElement.isStatic) { 268 } else if (staticElement.isStatic) {
58 shared.Element classElement = staticElement.enclosingElement;
59 return new AccessSemantics.staticField( 269 return new AccessSemantics.staticField(
60 node.methodName.name, 270 node.methodName,
61 staticElement.variable, 271 staticElement.variable,
62 classElement, 272 staticElement.enclosingElement,
63 isInvoke: true); 273 isInvoke: true);
64 } 274 }
65 } else { 275 } else {
66 if (staticElement.enclosingElement is CompilationUnitElement) { 276 if (staticElement.enclosingElement is CompilationUnitElement) {
67 return new AccessSemantics.staticProperty( 277 return new AccessSemantics.staticProperty(
68 node.methodName.name, 278 node.methodName,
69 staticElement, 279 staticElement,
70 null, 280 null,
71 isInvoke: true); 281 isInvoke: true);
72 } else if (staticElement.isStatic) { 282 } else if (staticElement.isStatic) {
73 shared.Element classElement = staticElement.enclosingElement;
74 return new AccessSemantics.staticProperty( 283 return new AccessSemantics.staticProperty(
75 node.methodName.name, 284 node.methodName,
76 staticElement, 285 staticElement,
77 classElement, 286 staticElement.enclosingElement,
78 isInvoke: true); 287 isInvoke: true);
79 } 288 }
80 } 289 }
81 } else if (staticElement is LocalVariableElement) { 290 } else if (staticElement is LocalVariableElement) {
82 return new AccessSemantics.localVariable( 291 return new AccessSemantics.localVariable(
83 node.methodName.name, 292 node.methodName,
84 staticElement, 293 staticElement,
85 isInvoke: true); 294 isInvoke: true);
86 } else if (staticElement is ParameterElement) { 295 } else if (staticElement is ParameterElement) {
87 return new AccessSemantics.parameter( 296 return new AccessSemantics.parameter(
88 node.methodName.name, 297 node.methodName,
89 staticElement, 298 staticElement,
90 isInvoke: true); 299 isInvoke: true);
91 } else if (staticElement is TypeParameterElement) { 300 } else if (staticElement is TypeParameterElement) {
92 return new AccessSemantics.typeParameter( 301 return new AccessSemantics.typeParameter(
93 node.methodName.name, 302 node.methodName,
94 staticElement, 303 staticElement,
95 isInvoke: true); 304 isInvoke: true);
96 } else if (staticElement is ClassElement || 305 } else if (staticElement is ClassElement ||
97 staticElement is FunctionTypeAliasElement || 306 staticElement is FunctionTypeAliasElement ||
98 staticElement is DynamicElementImpl) { 307 staticElement is DynamicElementImpl) {
99 return new AccessSemantics.toplevelType( 308 return new AccessSemantics.toplevelType(
100 node.methodName.name, 309 node.methodName,
101 staticElement, 310 staticElement,
102 isInvoke: true); 311 isInvoke: true);
103 } 312 }
104 } else if (target is Identifier) { 313 } else if (target is Identifier) {
105 Element targetStaticElement = target.staticElement; 314 Element targetStaticElement = target.staticElement;
106 if (targetStaticElement is PrefixElement) { 315 if (targetStaticElement is PrefixElement) {
107 if (staticElement == null) { 316 if (staticElement == null) {
108 return new AccessSemantics.dynamic( 317 return new AccessSemantics.dynamic(
109 node.methodName.name, 318 node.methodName,
110 null, 319 null,
111 isInvoke: true); 320 isInvoke: true);
112 } else if (staticElement is PropertyAccessorElement) { 321 } else if (staticElement is PropertyAccessorElement) {
113 if (staticElement.isSynthetic) { 322 if (staticElement.isSynthetic) {
114 return new AccessSemantics.staticField( 323 return new AccessSemantics.staticField(
115 node.methodName.name, 324 node.methodName,
116 staticElement.variable, 325 staticElement.variable,
117 null, 326 null,
118 isInvoke: true); 327 isInvoke: true);
119 } else { 328 } else {
120 return new AccessSemantics.staticProperty( 329 return new AccessSemantics.staticProperty(
121 node.methodName.name, 330 node.methodName,
122 staticElement, 331 staticElement,
123 null, 332 null,
124 isInvoke: true); 333 isInvoke: true);
125 } 334 }
126 } else if (staticElement is TypeParameterElement) { 335 } else if (staticElement is TypeParameterElement) {
127 return new AccessSemantics.typeParameter( 336 return new AccessSemantics.typeParameter(
128 node.methodName.name, 337 node.methodName,
129 staticElement, 338 staticElement,
130 isInvoke: true); 339 isInvoke: true);
131 } else if (staticElement is ClassElement || 340 } else if (staticElement is ClassElement ||
132 staticElement is FunctionTypeAliasElement) { 341 staticElement is FunctionTypeAliasElement) {
133 return new AccessSemantics.toplevelType( 342 return new AccessSemantics.toplevelType(
134 node.methodName.name, 343 node.methodName,
135 staticElement, 344 staticElement,
136 isInvoke: true); 345 isInvoke: true);
137 } else { 346 } else {
138 return new AccessSemantics.staticMethod( 347 return new AccessSemantics.staticMethod(
139 node.methodName.name, 348 node.methodName,
140 staticElement, 349 staticElement,
141 null, 350 null,
142 isInvoke: true); 351 isInvoke: true);
143 } 352 }
144 } else if (targetStaticElement is ClassElement) { 353 } else if (targetStaticElement is ClassElement) {
145 if (staticElement is PropertyAccessorElement) { 354 if (staticElement is PropertyAccessorElement) {
146 if (staticElement.isSynthetic) { 355 if (staticElement.isSynthetic) {
147 return new AccessSemantics.staticField( 356 return new AccessSemantics.staticField(
148 node.methodName.name, 357 node.methodName,
149 staticElement.variable, 358 staticElement.variable,
150 targetStaticElement, 359 targetStaticElement,
151 isInvoke: true); 360 isInvoke: true);
152 } else { 361 } else {
153 return new AccessSemantics.staticProperty( 362 return new AccessSemantics.staticProperty(
154 node.methodName.name, 363 node.methodName,
155 staticElement, 364 staticElement,
156 targetStaticElement, 365 targetStaticElement,
157 isInvoke: true); 366 isInvoke: true);
158 } 367 }
159 } else { 368 } else {
160 return new AccessSemantics.staticMethod( 369 return new AccessSemantics.staticMethod(
161 node.methodName.name, 370 node.methodName,
162 staticElement, 371 staticElement,
163 targetStaticElement, 372 targetStaticElement,
164 isInvoke: true); 373 isInvoke: true);
165 } 374 }
166 } 375 }
167 } 376 }
168 return new AccessSemantics.dynamic( 377 return new AccessSemantics.dynamic(node.methodName, target, isInvoke: true);
169 node.methodName.name, target, isInvoke: true);
170 } 378 }
171 379
172 /** 380 /**
173 * Return the access semantics for [node]. 381 * Return the access semantics for [node].
174 */ 382 */
175 @override 383 @override
176 AccessSemantics visitPrefixedIdentifier(PrefixedIdentifier node) { 384 AccessSemantics visitPrefixedIdentifier(PrefixedIdentifier node) {
177 return _classifyPrefixed(node.prefix, node.identifier); 385 return _classifyPrefixed(node.prefix, node.identifier);
178 } 386 }
179 387
180 /** 388 /**
181 * Return the access semantics for [node]. 389 * Return the access semantics for [node].
182 */ 390 */
183 @override 391 @override
184 AccessSemantics visitPropertyAccess(PropertyAccess node) { 392 AccessSemantics visitPropertyAccess(PropertyAccess node) {
185 if (node.target is Identifier) { 393 if (node.target is Identifier) {
186 return _classifyPrefixed(node.target, node.propertyName); 394 return _classifyPrefixed(node.target, node.propertyName);
187 } else { 395 } else {
188 return new AccessSemantics.dynamic( 396 return new AccessSemantics.dynamic(node.propertyName, node.realTarget);
189 node.propertyName.name,
190 node.realTarget,
191 isRead: node.propertyName.inGetterContext(),
192 isWrite: node.propertyName.inSetterContext());
193 } 397 }
194 } 398 }
195 399
196 /** 400 /**
197 * Return the access semantics for [node]. 401 * Return the access semantics for [node].
198 * 402 *
199 * Note: if [node] is the right hand side of a [PropertyAccess] or 403 * Note: if [node] is the right hand side of a [PropertyAccess] or
200 * [PrefixedIdentifier], or the method name of a [MethodInvocation], the retur n 404 * [PrefixedIdentifier], or the method name of a [MethodInvocation], the retur n
201 * value is null, since the semantics are determined by the parent. In 405 * value is null, since the semantics are determined by the parent. In
202 * practice these cases should never arise because the parent will visit the 406 * practice these cases should never arise because the parent will visit the
(...skipping 15 matching lines...) Expand all
218 (parent is MethodInvocation && parent.methodName == node)) { 422 (parent is MethodInvocation && parent.methodName == node)) {
219 // The access semantics are determined by the parent. 423 // The access semantics are determined by the parent.
220 return null; 424 return null;
221 } 425 }
222 // TODO(paulberry): handle PrefixElement. 426 // TODO(paulberry): handle PrefixElement.
223 Element staticElement = node.staticElement; 427 Element staticElement = node.staticElement;
224 if (staticElement is PropertyAccessorElement) { 428 if (staticElement is PropertyAccessorElement) {
225 if (staticElement.isSynthetic) { 429 if (staticElement.isSynthetic) {
226 if (staticElement.enclosingElement is CompilationUnitElement) { 430 if (staticElement.enclosingElement is CompilationUnitElement) {
227 return new AccessSemantics.staticField( 431 return new AccessSemantics.staticField(
228 node.name, 432 node,
229 staticElement.variable, 433 staticElement.variable,
230 null, 434 null);
231 isRead: node.inGetterContext(),
232 isWrite: node.inSetterContext());
233 } else if (staticElement.isStatic) { 435 } else if (staticElement.isStatic) {
234 shared.Element classElement = staticElement.enclosingElement;
235 return new AccessSemantics.staticField( 436 return new AccessSemantics.staticField(
236 node.name, 437 node,
237 staticElement.variable, 438 staticElement.variable,
238 classElement, 439 staticElement.enclosingElement);
239 isRead: node.inGetterContext(),
240 isWrite: node.inSetterContext());
241 } 440 }
242 } else { 441 } else {
243 if (staticElement.enclosingElement is CompilationUnitElement) { 442 if (staticElement.enclosingElement is CompilationUnitElement) {
443 return new AccessSemantics.staticProperty(node, staticElement, null);
444 } else if (staticElement.isStatic) {
244 return new AccessSemantics.staticProperty( 445 return new AccessSemantics.staticProperty(
245 node.name, 446 node,
246 staticElement, 447 staticElement,
247 null, 448 staticElement.enclosingElement);
248 isRead: node.inGetterContext(),
249 isWrite: node.inSetterContext());
250 } else if (staticElement.isStatic) {
251 shared.Element classElement = staticElement.enclosingElement;
252 return new AccessSemantics.staticProperty(
253 node.name,
254 staticElement,
255 classElement,
256 isRead: node.inGetterContext(),
257 isWrite: node.inSetterContext());
258 } 449 }
259 } 450 }
260 } else if (staticElement is LocalVariableElement) { 451 } else if (staticElement is LocalVariableElement) {
261 return new AccessSemantics.localVariable( 452 return new AccessSemantics.localVariable(node, staticElement);
262 node.name,
263 staticElement,
264 isRead: node.inGetterContext(),
265 isWrite: node.inSetterContext());
266 } else if (staticElement is ParameterElement) { 453 } else if (staticElement is ParameterElement) {
267 return new AccessSemantics.parameter( 454 return new AccessSemantics.parameter(node, staticElement);
268 node.name,
269 staticElement,
270 isRead: node.inGetterContext(),
271 isWrite: node.inSetterContext());
272 } else if (staticElement is FunctionElement) { 455 } else if (staticElement is FunctionElement) {
273 if (staticElement.enclosingElement is CompilationUnitElement) { 456 if (staticElement.enclosingElement is CompilationUnitElement) {
274 return new AccessSemantics.staticMethod( 457 return new AccessSemantics.staticMethod(node, staticElement, null);
275 node.name,
276 staticElement,
277 null,
278 isRead: node.inGetterContext(),
279 isWrite: node.inSetterContext());
280 } else { 458 } else {
281 return new AccessSemantics.localFunction( 459 return new AccessSemantics.localFunction(node, staticElement);
282 node.name,
283 staticElement,
284 isRead: node.inGetterContext(),
285 isWrite: node.inSetterContext());
286 } 460 }
287 } else if (staticElement is MethodElement && staticElement.isStatic) { 461 } else if (staticElement is MethodElement && staticElement.isStatic) {
288 return new AccessSemantics.staticMethod( 462 return new AccessSemantics.staticMethod(
289 node.name, 463 node,
290 staticElement, 464 staticElement,
291 staticElement.enclosingElement, 465 staticElement.enclosingElement);
292 isRead: node.inGetterContext(),
293 isWrite: node.inSetterContext());
294 } else if (staticElement is TypeParameterElement) { 466 } else if (staticElement is TypeParameterElement) {
295 return new AccessSemantics.typeParameter( 467 return new AccessSemantics.typeParameter(node, staticElement);
296 node.name,
297 staticElement,
298 isRead: node.inGetterContext(),
299 isWrite: node.inSetterContext());
300 } else if (staticElement is ClassElement || 468 } else if (staticElement is ClassElement ||
301 staticElement is FunctionTypeAliasElement || 469 staticElement is FunctionTypeAliasElement ||
302 staticElement is DynamicElementImpl) { 470 staticElement is DynamicElementImpl) {
303 return new AccessSemantics.toplevelType( 471 return new AccessSemantics.toplevelType(node, staticElement);
304 node.name,
305 staticElement,
306 isRead: node.inGetterContext(),
307 isWrite: node.inSetterContext());
308 } 472 }
309 return new AccessSemantics.dynamic( 473 return new AccessSemantics.dynamic(node, null);
310 node.name,
311 null,
312 isRead: node.inGetterContext(),
313 isWrite: node.inSetterContext());
314 } 474 }
315 475
316 /** 476 /**
317 * Helper function for classifying an expression of type 477 * Helper function for classifying an expression of type
318 * Identifier.SimpleIdentifier. 478 * Identifier.SimpleIdentifier.
319 */ 479 */
320 AccessSemantics _classifyPrefixed(Identifier lhs, SimpleIdentifier rhs) { 480 AccessSemantics _classifyPrefixed(Identifier lhs, SimpleIdentifier rhs) {
321 Element lhsElement = lhs.staticElement; 481 Element lhsElement = lhs.staticElement;
322 Element rhsElement = rhs.staticElement; 482 Element rhsElement = rhs.staticElement;
323 if (lhsElement is PrefixElement) { 483 if (lhsElement is PrefixElement) {
324 if (rhsElement is PropertyAccessorElement) { 484 if (rhsElement is PropertyAccessorElement) {
325 if (rhsElement.isSynthetic) { 485 if (rhsElement.isSynthetic) {
326 return new AccessSemantics.staticField( 486 return new AccessSemantics.staticField(
327 rhs.name, 487 rhs,
328 rhsElement.variable, 488 rhsElement.variable,
329 null, 489 null);
330 isRead: rhs.inGetterContext(),
331 isWrite: rhs.inSetterContext());
332 } else { 490 } else {
333 return new AccessSemantics.staticProperty( 491 return new AccessSemantics.staticProperty(rhs, rhsElement, null);
334 rhs.name,
335 rhsElement,
336 null,
337 isRead: rhs.inGetterContext(),
338 isWrite: rhs.inSetterContext());
339 } 492 }
340 } else if (rhsElement is FunctionElement) { 493 } else if (rhsElement is FunctionElement) {
341 return new AccessSemantics.staticMethod( 494 return new AccessSemantics.staticMethod(rhs, rhsElement, null);
342 rhs.name,
343 rhsElement,
344 null,
345 isRead: rhs.inGetterContext(),
346 isWrite: rhs.inSetterContext());
347 } else if (rhsElement is ClassElement || 495 } else if (rhsElement is ClassElement ||
348 rhsElement is FunctionTypeAliasElement) { 496 rhsElement is FunctionTypeAliasElement) {
349 return new AccessSemantics.toplevelType( 497 return new AccessSemantics.toplevelType(rhs, rhsElement);
350 rhs.name,
351 rhsElement,
352 isRead: rhs.inGetterContext(),
353 isWrite: rhs.inSetterContext());
354 } else { 498 } else {
355 return new AccessSemantics.dynamic( 499 return new AccessSemantics.dynamic(rhs, null);
356 rhs.name,
357 null,
358 isRead: rhs.inGetterContext(),
359 isWrite: rhs.inSetterContext());
360 } 500 }
361 } else if (lhsElement is ClassElement) { 501 } else if (lhsElement is ClassElement) {
362 if (rhsElement is PropertyAccessorElement && rhsElement.isSynthetic) { 502 if (rhsElement is PropertyAccessorElement && rhsElement.isSynthetic) {
363 return new AccessSemantics.staticField( 503 return new AccessSemantics.staticField(
364 rhs.name, 504 rhs,
365 rhsElement.variable, 505 rhsElement.variable,
366 lhsElement, 506 lhsElement);
367 isRead: rhs.inGetterContext(),
368 isWrite: rhs.inSetterContext());
369 } else if (rhsElement is MethodElement) { 507 } else if (rhsElement is MethodElement) {
370 return new AccessSemantics.staticMethod( 508 return new AccessSemantics.staticMethod(rhs, rhsElement, lhsElement);
371 rhs.name,
372 rhsElement,
373 lhsElement,
374 isRead: rhs.inGetterContext(),
375 isWrite: rhs.inSetterContext());
376 } else { 509 } else {
377 return new AccessSemantics.staticProperty( 510 return new AccessSemantics.staticProperty(rhs, rhsElement, lhsElement);
378 rhs.name,
379 rhsElement,
380 lhsElement,
381 isRead: rhs.inGetterContext(),
382 isWrite: rhs.inSetterContext());
383 } 511 }
384 } else { 512 } else {
385 return new AccessSemantics.dynamic( 513 return new AccessSemantics.dynamic(rhs, lhs);
386 rhs.name,
387 lhs,
388 isRead: rhs.inGetterContext(),
389 isWrite: rhs.inSetterContext());
390 } 514 }
391 } 515 }
392 } 516 }
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/lib/src/cps_generator.dart ('k') | pkg/analyzer2dart/lib/src/semantic_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698