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

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

Issue 898113002: 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
12 15
13 // TODO(johnniwinther,paulberry): This should be a constant. 16 // TODO(johnniwinther,paulberry): This should be a constant.
14 final AccessSemanticsVisitor ACCESS_SEMANTICS_VISITOR = 17 final AccessSemanticsVisitor ACCESS_SEMANTICS_VISITOR =
15 new AccessSemanticsVisitor(); 18 new AccessSemanticsVisitor();
16 19
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
231 // TODO(johnniwinther,paulberry): This should extend a non-recursive visitor. 20 // TODO(johnniwinther,paulberry): This should extend a non-recursive visitor.
232 class AccessSemanticsVisitor extends RecursiveAstVisitor<AccessSemantics> { 21 class AccessSemanticsVisitor extends RecursiveAstVisitor<AccessSemantics> {
233 /** 22 /**
234 * Return the semantics for [node]. 23 * Return the semantics for [node].
235 */ 24 */
236 @override 25 @override
237 AccessSemantics visitMethodInvocation(MethodInvocation node) { 26 AccessSemantics visitMethodInvocation(MethodInvocation node) {
238 Expression target = node.realTarget; 27 Expression target = node.realTarget;
239 Element staticElement = node.methodName.staticElement; 28 Element staticElement = node.methodName.staticElement;
240 if (target == null) { 29 if (target == null) {
241 if (staticElement is FunctionElement) { 30 if (staticElement is FunctionElement) {
242 if (staticElement.enclosingElement is CompilationUnitElement) { 31 if (staticElement.enclosingElement is CompilationUnitElement) {
243 return new AccessSemantics.staticMethod( 32 return new AccessSemantics.staticMethod(
244 node.methodName, 33 node.methodName.name,
245 staticElement, 34 staticElement,
246 null, 35 null,
247 isInvoke: true); 36 isInvoke: true);
248 } else { 37 } else {
249 return new AccessSemantics.localFunction( 38 return new AccessSemantics.localFunction(
250 node.methodName, 39 node.methodName.name,
251 staticElement, 40 staticElement,
252 isInvoke: true); 41 isInvoke: true);
253 } 42 }
254 } else if (staticElement is MethodElement && staticElement.isStatic) { 43 } else if (staticElement is MethodElement && staticElement.isStatic) {
255 return new AccessSemantics.staticMethod( 44 return new AccessSemantics.staticMethod(
256 node.methodName, 45 node.methodName.name,
257 staticElement, 46 staticElement,
258 staticElement.enclosingElement, 47 staticElement.enclosingElement,
259 isInvoke: true); 48 isInvoke: true);
260 } else if (staticElement is PropertyAccessorElement) { 49 } else if (staticElement is PropertyAccessorElement) {
261 if (staticElement.isSynthetic) { 50 if (staticElement.isSynthetic) {
262 if (staticElement.enclosingElement is CompilationUnitElement) { 51 if (staticElement.enclosingElement is CompilationUnitElement) {
263 return new AccessSemantics.staticField( 52 return new AccessSemantics.staticField(
264 node.methodName, 53 node.methodName.name,
265 staticElement.variable, 54 staticElement.variable,
266 null, 55 null,
267 isInvoke: true); 56 isInvoke: true);
268 } else if (staticElement.isStatic) { 57 } else if (staticElement.isStatic) {
58 shared.Element classElement = staticElement.enclosingElement;
269 return new AccessSemantics.staticField( 59 return new AccessSemantics.staticField(
270 node.methodName, 60 node.methodName.name,
271 staticElement.variable, 61 staticElement.variable,
272 staticElement.enclosingElement, 62 classElement,
273 isInvoke: true); 63 isInvoke: true);
274 } 64 }
275 } else { 65 } else {
276 if (staticElement.enclosingElement is CompilationUnitElement) { 66 if (staticElement.enclosingElement is CompilationUnitElement) {
277 return new AccessSemantics.staticProperty( 67 return new AccessSemantics.staticProperty(
278 node.methodName, 68 node.methodName.name,
279 staticElement, 69 staticElement,
280 null, 70 null,
281 isInvoke: true); 71 isInvoke: true);
282 } else if (staticElement.isStatic) { 72 } else if (staticElement.isStatic) {
73 shared.Element classElement = staticElement.enclosingElement;
283 return new AccessSemantics.staticProperty( 74 return new AccessSemantics.staticProperty(
284 node.methodName, 75 node.methodName.name,
285 staticElement, 76 staticElement,
286 staticElement.enclosingElement, 77 classElement,
287 isInvoke: true); 78 isInvoke: true);
288 } 79 }
289 } 80 }
290 } else if (staticElement is LocalVariableElement) { 81 } else if (staticElement is LocalVariableElement) {
291 return new AccessSemantics.localVariable( 82 return new AccessSemantics.localVariable(
292 node.methodName, 83 node.methodName.name,
293 staticElement, 84 staticElement,
294 isInvoke: true); 85 isInvoke: true);
295 } else if (staticElement is ParameterElement) { 86 } else if (staticElement is ParameterElement) {
296 return new AccessSemantics.parameter( 87 return new AccessSemantics.parameter(
297 node.methodName, 88 node.methodName.name,
298 staticElement, 89 staticElement,
299 isInvoke: true); 90 isInvoke: true);
300 } else if (staticElement is TypeParameterElement) { 91 } else if (staticElement is TypeParameterElement) {
301 return new AccessSemantics.typeParameter( 92 return new AccessSemantics.typeParameter(
302 node.methodName, 93 node.methodName.name,
303 staticElement, 94 staticElement,
304 isInvoke: true); 95 isInvoke: true);
305 } else if (staticElement is ClassElement || 96 } else if (staticElement is ClassElement ||
306 staticElement is FunctionTypeAliasElement || 97 staticElement is FunctionTypeAliasElement ||
307 staticElement is DynamicElementImpl) { 98 staticElement is DynamicElementImpl) {
308 return new AccessSemantics.toplevelType( 99 return new AccessSemantics.toplevelType(
309 node.methodName, 100 node.methodName.name,
310 staticElement, 101 staticElement,
311 isInvoke: true); 102 isInvoke: true);
312 } 103 }
313 } else if (target is Identifier) { 104 } else if (target is Identifier) {
314 Element targetStaticElement = target.staticElement; 105 Element targetStaticElement = target.staticElement;
315 if (targetStaticElement is PrefixElement) { 106 if (targetStaticElement is PrefixElement) {
316 if (staticElement == null) { 107 if (staticElement == null) {
317 return new AccessSemantics.dynamic( 108 return new AccessSemantics.dynamic(
318 node.methodName, 109 node.methodName.name,
319 null, 110 null,
320 isInvoke: true); 111 isInvoke: true);
321 } else if (staticElement is PropertyAccessorElement) { 112 } else if (staticElement is PropertyAccessorElement) {
322 if (staticElement.isSynthetic) { 113 if (staticElement.isSynthetic) {
323 return new AccessSemantics.staticField( 114 return new AccessSemantics.staticField(
324 node.methodName, 115 node.methodName.name,
325 staticElement.variable, 116 staticElement.variable,
326 null, 117 null,
327 isInvoke: true); 118 isInvoke: true);
328 } else { 119 } else {
329 return new AccessSemantics.staticProperty( 120 return new AccessSemantics.staticProperty(
330 node.methodName, 121 node.methodName.name,
331 staticElement, 122 staticElement,
332 null, 123 null,
333 isInvoke: true); 124 isInvoke: true);
334 } 125 }
335 } else if (staticElement is TypeParameterElement) { 126 } else if (staticElement is TypeParameterElement) {
336 return new AccessSemantics.typeParameter( 127 return new AccessSemantics.typeParameter(
337 node.methodName, 128 node.methodName.name,
338 staticElement, 129 staticElement,
339 isInvoke: true); 130 isInvoke: true);
340 } else if (staticElement is ClassElement || 131 } else if (staticElement is ClassElement ||
341 staticElement is FunctionTypeAliasElement) { 132 staticElement is FunctionTypeAliasElement) {
342 return new AccessSemantics.toplevelType( 133 return new AccessSemantics.toplevelType(
343 node.methodName, 134 node.methodName.name,
344 staticElement, 135 staticElement,
345 isInvoke: true); 136 isInvoke: true);
346 } else { 137 } else {
347 return new AccessSemantics.staticMethod( 138 return new AccessSemantics.staticMethod(
348 node.methodName, 139 node.methodName.name,
349 staticElement, 140 staticElement,
350 null, 141 null,
351 isInvoke: true); 142 isInvoke: true);
352 } 143 }
353 } else if (targetStaticElement is ClassElement) { 144 } else if (targetStaticElement is ClassElement) {
354 if (staticElement is PropertyAccessorElement) { 145 if (staticElement is PropertyAccessorElement) {
355 if (staticElement.isSynthetic) { 146 if (staticElement.isSynthetic) {
356 return new AccessSemantics.staticField( 147 return new AccessSemantics.staticField(
357 node.methodName, 148 node.methodName.name,
358 staticElement.variable, 149 staticElement.variable,
359 targetStaticElement, 150 targetStaticElement,
360 isInvoke: true); 151 isInvoke: true);
361 } else { 152 } else {
362 return new AccessSemantics.staticProperty( 153 return new AccessSemantics.staticProperty(
363 node.methodName, 154 node.methodName.name,
364 staticElement, 155 staticElement,
365 targetStaticElement, 156 targetStaticElement,
366 isInvoke: true); 157 isInvoke: true);
367 } 158 }
368 } else { 159 } else {
369 return new AccessSemantics.staticMethod( 160 return new AccessSemantics.staticMethod(
370 node.methodName, 161 node.methodName.name,
371 staticElement, 162 staticElement,
372 targetStaticElement, 163 targetStaticElement,
373 isInvoke: true); 164 isInvoke: true);
374 } 165 }
375 } 166 }
376 } 167 }
377 return new AccessSemantics.dynamic(node.methodName, target, isInvoke: true); 168 return new AccessSemantics.dynamic(
169 node.methodName.name, target, isInvoke: true);
378 } 170 }
379 171
380 /** 172 /**
381 * Return the access semantics for [node]. 173 * Return the access semantics for [node].
382 */ 174 */
383 @override 175 @override
384 AccessSemantics visitPrefixedIdentifier(PrefixedIdentifier node) { 176 AccessSemantics visitPrefixedIdentifier(PrefixedIdentifier node) {
385 return _classifyPrefixed(node.prefix, node.identifier); 177 return _classifyPrefixed(node.prefix, node.identifier);
386 } 178 }
387 179
388 /** 180 /**
389 * Return the access semantics for [node]. 181 * Return the access semantics for [node].
390 */ 182 */
391 @override 183 @override
392 AccessSemantics visitPropertyAccess(PropertyAccess node) { 184 AccessSemantics visitPropertyAccess(PropertyAccess node) {
393 if (node.target is Identifier) { 185 if (node.target is Identifier) {
394 return _classifyPrefixed(node.target, node.propertyName); 186 return _classifyPrefixed(node.target, node.propertyName);
395 } else { 187 } else {
396 return new AccessSemantics.dynamic(node.propertyName, node.realTarget); 188 return new AccessSemantics.dynamic(
189 node.propertyName.name,
190 node.realTarget,
191 isRead: node.propertyName.inGetterContext(),
192 isWrite: node.propertyName.inSetterContext());
397 } 193 }
398 } 194 }
399 195
400 /** 196 /**
401 * Return the access semantics for [node]. 197 * Return the access semantics for [node].
402 * 198 *
403 * Note: if [node] is the right hand side of a [PropertyAccess] or 199 * Note: if [node] is the right hand side of a [PropertyAccess] or
404 * [PrefixedIdentifier], or the method name of a [MethodInvocation], the retur n 200 * [PrefixedIdentifier], or the method name of a [MethodInvocation], the retur n
405 * value is null, since the semantics are determined by the parent. In 201 * value is null, since the semantics are determined by the parent. In
406 * practice these cases should never arise because the parent will visit the 202 * practice these cases should never arise because the parent will visit the
(...skipping 15 matching lines...) Expand all
422 (parent is MethodInvocation && parent.methodName == node)) { 218 (parent is MethodInvocation && parent.methodName == node)) {
423 // The access semantics are determined by the parent. 219 // The access semantics are determined by the parent.
424 return null; 220 return null;
425 } 221 }
426 // TODO(paulberry): handle PrefixElement. 222 // TODO(paulberry): handle PrefixElement.
427 Element staticElement = node.staticElement; 223 Element staticElement = node.staticElement;
428 if (staticElement is PropertyAccessorElement) { 224 if (staticElement is PropertyAccessorElement) {
429 if (staticElement.isSynthetic) { 225 if (staticElement.isSynthetic) {
430 if (staticElement.enclosingElement is CompilationUnitElement) { 226 if (staticElement.enclosingElement is CompilationUnitElement) {
431 return new AccessSemantics.staticField( 227 return new AccessSemantics.staticField(
432 node, 228 node.name,
433 staticElement.variable, 229 staticElement.variable,
434 null); 230 null,
231 isRead: node.inGetterContext(),
232 isWrite: node.inSetterContext());
435 } else if (staticElement.isStatic) { 233 } else if (staticElement.isStatic) {
234 shared.Element classElement = staticElement.enclosingElement;
436 return new AccessSemantics.staticField( 235 return new AccessSemantics.staticField(
437 node, 236 node.name,
438 staticElement.variable, 237 staticElement.variable,
439 staticElement.enclosingElement); 238 classElement,
239 isRead: node.inGetterContext(),
240 isWrite: node.inSetterContext());
440 } 241 }
441 } else { 242 } else {
442 if (staticElement.enclosingElement is CompilationUnitElement) { 243 if (staticElement.enclosingElement is CompilationUnitElement) {
443 return new AccessSemantics.staticProperty(node, staticElement, null); 244 return new AccessSemantics.staticProperty(
245 node.name,
246 staticElement,
247 null,
248 isRead: node.inGetterContext(),
249 isWrite: node.inSetterContext());
444 } else if (staticElement.isStatic) { 250 } else if (staticElement.isStatic) {
251 shared.Element classElement = staticElement.enclosingElement;
445 return new AccessSemantics.staticProperty( 252 return new AccessSemantics.staticProperty(
446 node, 253 node.name,
447 staticElement, 254 staticElement,
448 staticElement.enclosingElement); 255 classElement,
256 isRead: node.inGetterContext(),
257 isWrite: node.inSetterContext());
449 } 258 }
450 } 259 }
451 } else if (staticElement is LocalVariableElement) { 260 } else if (staticElement is LocalVariableElement) {
452 return new AccessSemantics.localVariable(node, staticElement); 261 return new AccessSemantics.localVariable(
262 node.name,
263 staticElement,
264 isRead: node.inGetterContext(),
265 isWrite: node.inSetterContext());
453 } else if (staticElement is ParameterElement) { 266 } else if (staticElement is ParameterElement) {
454 return new AccessSemantics.parameter(node, staticElement); 267 return new AccessSemantics.parameter(
268 node.name,
269 staticElement,
270 isRead: node.inGetterContext(),
271 isWrite: node.inSetterContext());
455 } else if (staticElement is FunctionElement) { 272 } else if (staticElement is FunctionElement) {
456 if (staticElement.enclosingElement is CompilationUnitElement) { 273 if (staticElement.enclosingElement is CompilationUnitElement) {
457 return new AccessSemantics.staticMethod(node, staticElement, null); 274 return new AccessSemantics.staticMethod(
275 node.name,
276 staticElement,
277 null,
278 isRead: node.inGetterContext(),
279 isWrite: node.inSetterContext());
458 } else { 280 } else {
459 return new AccessSemantics.localFunction(node, staticElement); 281 return new AccessSemantics.localFunction(
282 node.name,
283 staticElement,
284 isRead: node.inGetterContext(),
285 isWrite: node.inSetterContext());
460 } 286 }
461 } else if (staticElement is MethodElement && staticElement.isStatic) { 287 } else if (staticElement is MethodElement && staticElement.isStatic) {
462 return new AccessSemantics.staticMethod( 288 return new AccessSemantics.staticMethod(
463 node, 289 node.name,
464 staticElement, 290 staticElement,
465 staticElement.enclosingElement); 291 staticElement.enclosingElement,
292 isRead: node.inGetterContext(),
293 isWrite: node.inSetterContext());
466 } else if (staticElement is TypeParameterElement) { 294 } else if (staticElement is TypeParameterElement) {
467 return new AccessSemantics.typeParameter(node, staticElement); 295 return new AccessSemantics.typeParameter(
296 node.name,
297 staticElement,
298 isRead: node.inGetterContext(),
299 isWrite: node.inSetterContext());
468 } else if (staticElement is ClassElement || 300 } else if (staticElement is ClassElement ||
469 staticElement is FunctionTypeAliasElement || 301 staticElement is FunctionTypeAliasElement ||
470 staticElement is DynamicElementImpl) { 302 staticElement is DynamicElementImpl) {
471 return new AccessSemantics.toplevelType(node, staticElement); 303 return new AccessSemantics.toplevelType(
304 node.name,
305 staticElement,
306 isRead: node.inGetterContext(),
307 isWrite: node.inSetterContext());
472 } 308 }
473 return new AccessSemantics.dynamic(node, null); 309 return new AccessSemantics.dynamic(
310 node.name,
311 null,
312 isRead: node.inGetterContext(),
313 isWrite: node.inSetterContext());
474 } 314 }
475 315
476 /** 316 /**
477 * Helper function for classifying an expression of type 317 * Helper function for classifying an expression of type
478 * Identifier.SimpleIdentifier. 318 * Identifier.SimpleIdentifier.
479 */ 319 */
480 AccessSemantics _classifyPrefixed(Identifier lhs, SimpleIdentifier rhs) { 320 AccessSemantics _classifyPrefixed(Identifier lhs, SimpleIdentifier rhs) {
481 Element lhsElement = lhs.staticElement; 321 Element lhsElement = lhs.staticElement;
482 Element rhsElement = rhs.staticElement; 322 Element rhsElement = rhs.staticElement;
483 if (lhsElement is PrefixElement) { 323 if (lhsElement is PrefixElement) {
484 if (rhsElement is PropertyAccessorElement) { 324 if (rhsElement is PropertyAccessorElement) {
485 if (rhsElement.isSynthetic) { 325 if (rhsElement.isSynthetic) {
486 return new AccessSemantics.staticField( 326 return new AccessSemantics.staticField(
487 rhs, 327 rhs.name,
488 rhsElement.variable, 328 rhsElement.variable,
489 null); 329 null,
330 isRead: rhs.inGetterContext(),
331 isWrite: rhs.inSetterContext());
490 } else { 332 } else {
491 return new AccessSemantics.staticProperty(rhs, rhsElement, null); 333 return new AccessSemantics.staticProperty(
334 rhs.name,
335 rhsElement,
336 null,
337 isRead: rhs.inGetterContext(),
338 isWrite: rhs.inSetterContext());
492 } 339 }
493 } else if (rhsElement is FunctionElement) { 340 } else if (rhsElement is FunctionElement) {
494 return new AccessSemantics.staticMethod(rhs, rhsElement, null); 341 return new AccessSemantics.staticMethod(
342 rhs.name,
343 rhsElement,
344 null,
345 isRead: rhs.inGetterContext(),
346 isWrite: rhs.inSetterContext());
495 } else if (rhsElement is ClassElement || 347 } else if (rhsElement is ClassElement ||
496 rhsElement is FunctionTypeAliasElement) { 348 rhsElement is FunctionTypeAliasElement) {
497 return new AccessSemantics.toplevelType(rhs, rhsElement); 349 return new AccessSemantics.toplevelType(
350 rhs.name,
351 rhsElement,
352 isRead: rhs.inGetterContext(),
353 isWrite: rhs.inSetterContext());
498 } else { 354 } else {
499 return new AccessSemantics.dynamic(rhs, null); 355 return new AccessSemantics.dynamic(
356 rhs.name,
357 null,
358 isRead: rhs.inGetterContext(),
359 isWrite: rhs.inSetterContext());
500 } 360 }
501 } else if (lhsElement is ClassElement) { 361 } else if (lhsElement is ClassElement) {
502 if (rhsElement is PropertyAccessorElement && rhsElement.isSynthetic) { 362 if (rhsElement is PropertyAccessorElement && rhsElement.isSynthetic) {
503 return new AccessSemantics.staticField( 363 return new AccessSemantics.staticField(
504 rhs, 364 rhs.name,
505 rhsElement.variable, 365 rhsElement.variable,
506 lhsElement); 366 lhsElement,
367 isRead: rhs.inGetterContext(),
368 isWrite: rhs.inSetterContext());
507 } else if (rhsElement is MethodElement) { 369 } else if (rhsElement is MethodElement) {
508 return new AccessSemantics.staticMethod(rhs, rhsElement, lhsElement); 370 return new AccessSemantics.staticMethod(
371 rhs.name,
372 rhsElement,
373 lhsElement,
374 isRead: rhs.inGetterContext(),
375 isWrite: rhs.inSetterContext());
509 } else { 376 } else {
510 return new AccessSemantics.staticProperty(rhs, rhsElement, lhsElement); 377 return new AccessSemantics.staticProperty(
378 rhs.name,
379 rhsElement,
380 lhsElement,
381 isRead: rhs.inGetterContext(),
382 isWrite: rhs.inSetterContext());
511 } 383 }
512 } else { 384 } else {
513 return new AccessSemantics.dynamic(rhs, lhs); 385 return new AccessSemantics.dynamic(
386 rhs.name,
387 lhs,
388 isRead: rhs.inGetterContext(),
389 isWrite: rhs.inSetterContext());
514 } 390 }
515 } 391 }
516 } 392 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698