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.builder_accessors; | 5 library fasta.builder_accessors; |
6 | 6 |
7 export 'frontend_accessors.dart' show wrapInvalid; | 7 export 'frontend_accessors.dart' show wrapInvalid; |
8 | 8 |
9 import 'frontend_accessors.dart' show Accessor; | 9 import 'frontend_accessors.dart' show Accessor; |
10 | 10 |
| 11 import 'package:front_end/src/fasta/builder/shadow_ast.dart'; |
11 import 'package:kernel/ast.dart'; | 12 import 'package:kernel/ast.dart'; |
12 | 13 |
13 import '../errors.dart' show internalError; | 14 import '../errors.dart' show internalError; |
14 | 15 |
15 import '../builder/scope.dart' show AccessErrorBuilder, ProblemBuilder; | 16 import '../builder/scope.dart' show AccessErrorBuilder, ProblemBuilder; |
16 | 17 |
17 import 'frontend_accessors.dart' as kernel | 18 import 'frontend_accessors.dart' as kernel |
18 show | 19 show |
19 IndexAccessor, | 20 IndexAccessor, |
20 NullAwarePropertyAccessor, | 21 NullAwarePropertyAccessor, |
(...skipping 12 matching lines...) Expand all Loading... |
33 | 34 |
34 import '../names.dart' show callName; | 35 import '../names.dart' show callName; |
35 | 36 |
36 abstract class BuilderHelper { | 37 abstract class BuilderHelper { |
37 Uri get uri; | 38 Uri get uri; |
38 | 39 |
39 Constructor lookupConstructor(Name name, {bool isSuper}); | 40 Constructor lookupConstructor(Name name, {bool isSuper}); |
40 | 41 |
41 Expression toSuperMethodInvocation(MethodInvocation node); | 42 Expression toSuperMethodInvocation(MethodInvocation node); |
42 | 43 |
43 Expression toValue(node); | 44 ShadowExpression toValue(node); |
44 | 45 |
45 Member lookupSuperMember(Name name, {bool isSetter: false}); | 46 Member lookupSuperMember(Name name, {bool isSetter: false}); |
46 | 47 |
47 builderToFirstExpression(Builder builder, String name, int charOffset); | 48 builderToFirstExpression(Builder builder, String name, int charOffset); |
48 | 49 |
49 finishSend(Object receiver, Arguments arguments, int charOffset); | 50 finishSend(Object receiver, Arguments arguments, int charOffset); |
50 | 51 |
51 Expression buildCompileTimeError(error, [int charOffset]); | 52 ShadowExpression buildCompileTimeError(error, [int charOffset]); |
52 | 53 |
53 Initializer buildCompileTimeErrorIntializer(error, [int charOffset]); | 54 Initializer buildCompileTimeErrorIntializer(error, [int charOffset]); |
54 | 55 |
55 Expression buildStaticInvocation(Procedure target, Arguments arguments); | 56 Expression buildStaticInvocation(Procedure target, Arguments arguments); |
56 | 57 |
57 Expression buildProblemExpression(ProblemBuilder builder, int charOffset); | 58 ShadowExpression buildProblemExpression( |
| 59 ProblemBuilder builder, int charOffset); |
58 | 60 |
59 Expression throwNoSuchMethodError( | 61 ShadowExpression throwNoSuchMethodError( |
60 String name, Arguments arguments, int charOffset, | 62 String name, Arguments arguments, int charOffset, |
61 {bool isSuper: false, isGetter: false, isSetter: false}); | 63 {bool isSuper: false, isGetter: false, isSetter: false}); |
62 } | 64 } |
63 | 65 |
64 abstract class BuilderAccessor implements Accessor { | 66 abstract class BuilderAccessor implements Accessor { |
65 BuilderHelper get helper; | 67 BuilderHelper get helper; |
66 | 68 |
67 int get charOffset; | 69 int get charOffset; |
68 | 70 |
69 String get plainNameForRead; | 71 String get plainNameForRead; |
70 | 72 |
71 Uri get uri => helper.uri; | 73 Uri get uri => helper.uri; |
72 | 74 |
73 String get plainNameForWrite => plainNameForRead; | 75 String get plainNameForWrite => plainNameForRead; |
74 | 76 |
75 Expression buildForEffect() => buildSimpleRead(); | 77 ShadowExpression buildForEffect() => buildSimpleRead(); |
76 | 78 |
77 Initializer buildFieldInitializer( | 79 Initializer buildFieldInitializer( |
78 Map<String, FieldInitializer> initializers) { | 80 Map<String, FieldInitializer> initializers) { |
79 // TODO(ahe): This error message is really bad. | 81 // TODO(ahe): This error message is really bad. |
80 return helper.buildCompileTimeErrorIntializer( | 82 return helper.buildCompileTimeErrorIntializer( |
81 "Can't use $plainNameForRead here.", charOffset); | 83 "Can't use $plainNameForRead here.", charOffset); |
82 } | 84 } |
83 | 85 |
84 Expression makeInvalidRead() { | 86 Expression makeInvalidRead() { |
85 return buildThrowNoSuchMethodError(new Arguments.empty(), isGetter: true); | 87 return buildThrowNoSuchMethodError(new Arguments.empty(), isGetter: true); |
86 } | 88 } |
87 | 89 |
88 Expression makeInvalidWrite(Expression value) { | 90 Expression makeInvalidWrite(Expression value) { |
89 return buildThrowNoSuchMethodError(new Arguments(<Expression>[value]), | 91 return buildThrowNoSuchMethodError(new Arguments(<Expression>[value]), |
90 isSetter: true); | 92 isSetter: true); |
91 } | 93 } |
92 | 94 |
93 /* Expression | BuilderAccessor */ doInvocation( | 95 /* Expression | BuilderAccessor */ doInvocation( |
94 int charOffset, Arguments arguments); | 96 int charOffset, Arguments arguments); |
95 | 97 |
96 /* Expression | BuilderAccessor */ buildPropertyAccess( | 98 /* Expression | BuilderAccessor */ buildPropertyAccess( |
97 IncompleteSend send, bool isNullAware) { | 99 IncompleteSend send, bool isNullAware) { |
98 if (send is SendAccessor) { | 100 if (send is SendAccessor) { |
99 return buildMethodInvocation( | 101 return buildMethodInvocation(buildSimpleRead() as Expression, send.name, |
100 buildSimpleRead(), send.name, send.arguments, send.charOffset, | 102 send.arguments, send.charOffset, |
101 isNullAware: isNullAware); | 103 isNullAware: isNullAware); |
102 } else { | 104 } else { |
103 return PropertyAccessor.make(helper, send.charOffset, buildSimpleRead(), | 105 return PropertyAccessor.make(helper, send.charOffset, |
104 send.name, null, null, isNullAware); | 106 buildSimpleRead() as Expression, send.name, null, null, isNullAware); |
105 } | 107 } |
106 } | 108 } |
107 | 109 |
108 /* Expression | BuilderAccessor */ buildThrowNoSuchMethodError( | 110 /* Expression | BuilderAccessor */ buildThrowNoSuchMethodError( |
109 Arguments arguments, | 111 Arguments arguments, |
110 {bool isSuper: false, | 112 {bool isSuper: false, |
111 isGetter: false, | 113 isGetter: false, |
112 isSetter: false, | 114 isSetter: false, |
113 String name, | 115 String name, |
114 int charOffset}) { | 116 int charOffset}) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 Expression buildPostfixIncrement(Name binaryOperator, int charOffset, | 167 Expression buildPostfixIncrement(Name binaryOperator, int charOffset, |
166 {bool voidContext: false, Procedure interfaceTarget}) { | 168 {bool voidContext: false, Procedure interfaceTarget}) { |
167 return buildError(); | 169 return buildError(); |
168 } | 170 } |
169 | 171 |
170 Expression buildNullAwareAssignment(Expression value, DartType type, | 172 Expression buildNullAwareAssignment(Expression value, DartType type, |
171 {bool voidContext: false}) { | 173 {bool voidContext: false}) { |
172 return buildError(); | 174 return buildError(); |
173 } | 175 } |
174 | 176 |
175 Expression buildSimpleRead() => buildError(); | 177 ShadowExpression buildSimpleRead() => buildError() as ShadowExpression; |
176 | 178 |
177 Expression makeInvalidRead() => buildError(); | 179 Expression makeInvalidRead() => buildError(); |
178 | 180 |
179 Expression makeInvalidWrite(Expression value) => buildError(); | 181 Expression makeInvalidWrite(Expression value) => buildError(); |
180 } | 182 } |
181 | 183 |
182 class ThisAccessor extends BuilderAccessor { | 184 class ThisAccessor extends BuilderAccessor { |
183 final BuilderHelper helper; | 185 final BuilderHelper helper; |
184 | 186 |
185 final int charOffset; | 187 final int charOffset; |
186 | 188 |
187 final bool isInitializer; | 189 final bool isInitializer; |
188 | 190 |
189 final bool isSuper; | 191 final bool isSuper; |
190 | 192 |
191 ThisAccessor(this.helper, this.charOffset, this.isInitializer, | 193 ThisAccessor(this.helper, this.charOffset, this.isInitializer, |
192 {this.isSuper: false}); | 194 {this.isSuper: false}); |
193 | 195 |
194 String get plainNameForRead => internalError(isSuper ? "super" : "this"); | 196 String get plainNameForRead => internalError(isSuper ? "super" : "this"); |
195 | 197 |
196 Expression buildSimpleRead() { | 198 ShadowExpression buildSimpleRead() { |
197 if (!isSuper) { | 199 if (!isSuper) { |
198 return new ThisExpression(); | 200 return new ThisExpression() as ShadowExpression; |
199 } else { | 201 } else { |
200 return helper.buildCompileTimeError( | 202 return helper.buildCompileTimeError( |
201 "Can't use `super` as an expression.", charOffset); | 203 "Can't use `super` as an expression.", charOffset); |
202 } | 204 } |
203 } | 205 } |
204 | 206 |
205 Initializer buildFieldInitializer( | 207 Initializer buildFieldInitializer( |
206 Map<String, FieldInitializer> initializers) { | 208 Map<String, FieldInitializer> initializers) { |
207 String keyword = isSuper ? "super" : "this"; | 209 String keyword = isSuper ? "super" : "this"; |
208 return helper.buildCompileTimeErrorIntializer( | 210 return helper.buildCompileTimeErrorIntializer( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 281 } |
280 | 282 |
281 Expression buildPostfixIncrement(Name binaryOperator, int charOffset, | 283 Expression buildPostfixIncrement(Name binaryOperator, int charOffset, |
282 {bool voidContext: false, Procedure interfaceTarget}) { | 284 {bool voidContext: false, Procedure interfaceTarget}) { |
283 return buildAssignmentError(); | 285 return buildAssignmentError(); |
284 } | 286 } |
285 | 287 |
286 Expression buildAssignmentError() { | 288 Expression buildAssignmentError() { |
287 String message = | 289 String message = |
288 isSuper ? "Can't assign to 'super'." : "Can't assign to 'this'."; | 290 isSuper ? "Can't assign to 'super'." : "Can't assign to 'this'."; |
289 return helper.buildCompileTimeError(message, charOffset); | 291 return helper.buildCompileTimeError(message, charOffset) as Expression; |
290 } | 292 } |
291 | 293 |
292 toString() => "ThisAccessor($charOffset${isSuper ? ', super' : ''})"; | 294 toString() => "ThisAccessor($charOffset${isSuper ? ', super' : ''})"; |
293 } | 295 } |
294 | 296 |
295 abstract class IncompleteSend extends BuilderAccessor { | 297 abstract class IncompleteSend extends BuilderAccessor { |
296 final BuilderHelper helper; | 298 final BuilderHelper helper; |
297 | 299 |
298 final int charOffset; | 300 final int charOffset; |
299 | 301 |
300 final Name name; | 302 final Name name; |
301 | 303 |
302 IncompleteSend(this.helper, this.charOffset, this.name); | 304 IncompleteSend(this.helper, this.charOffset, this.name); |
303 | 305 |
304 withReceiver(Object receiver, {bool isNullAware}); | 306 withReceiver(Object receiver, {bool isNullAware}); |
305 } | 307 } |
306 | 308 |
307 class IncompleteError extends IncompleteSend with CompileTimeErrorAccessor { | 309 class IncompleteError extends IncompleteSend with CompileTimeErrorAccessor { |
308 final Object error; | 310 final Object error; |
309 | 311 |
310 IncompleteError(BuilderHelper helper, int charOffset, this.error) | 312 IncompleteError(BuilderHelper helper, int charOffset, this.error) |
311 : super(helper, charOffset, null); | 313 : super(helper, charOffset, null); |
312 | 314 |
313 Expression buildError() { | 315 Expression buildError() { |
314 return helper.buildCompileTimeError(error, charOffset); | 316 return helper.buildCompileTimeError(error, charOffset) as Expression; |
315 } | 317 } |
316 } | 318 } |
317 | 319 |
318 class SendAccessor extends IncompleteSend { | 320 class SendAccessor extends IncompleteSend { |
319 final Arguments arguments; | 321 final Arguments arguments; |
320 | 322 |
321 SendAccessor(BuilderHelper helper, int charOffset, Name name, this.arguments) | 323 SendAccessor(BuilderHelper helper, int charOffset, Name name, this.arguments) |
322 : super(helper, charOffset, name) { | 324 : super(helper, charOffset, name) { |
323 assert(arguments != null); | 325 assert(arguments != null); |
324 } | 326 } |
325 | 327 |
326 String get plainNameForRead => name.name; | 328 String get plainNameForRead => name.name; |
327 | 329 |
328 Expression buildSimpleRead() { | 330 ShadowExpression buildSimpleRead() { |
329 return internalError("Unhandled"); | 331 return internalError("Unhandled"); |
330 } | 332 } |
331 | 333 |
332 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 334 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
333 return internalError("Unhandled"); | 335 return internalError("Unhandled"); |
334 } | 336 } |
335 | 337 |
336 withReceiver(Object receiver, {bool isNullAware: false}) { | 338 withReceiver(Object receiver, {bool isNullAware: false}) { |
337 if (receiver is TypeDeclarationBuilder) { | 339 if (receiver is TypeDeclarationBuilder) { |
338 /// `SomeType?.toString` is the same as `SomeType.toString`, not | 340 /// `SomeType?.toString` is the same as `SomeType.toString`, not |
339 /// `(SomeType).toString`. | 341 /// `(SomeType).toString`. |
340 isNullAware = false; | 342 isNullAware = false; |
341 } | 343 } |
342 if (receiver is BuilderAccessor) { | 344 if (receiver is BuilderAccessor) { |
343 return receiver.buildPropertyAccess(this, isNullAware); | 345 return receiver.buildPropertyAccess(this, isNullAware); |
344 } | 346 } |
345 if (receiver is PrefixBuilder) { | 347 if (receiver is PrefixBuilder) { |
346 PrefixBuilder prefix = receiver; | 348 PrefixBuilder prefix = receiver; |
347 receiver = helper.builderToFirstExpression( | 349 receiver = helper.builderToFirstExpression( |
348 prefix.exports[name.name], "${prefix.name}.${name.name}", charOffset); | 350 prefix.exports[name.name], "${prefix.name}.${name.name}", charOffset); |
349 return helper.finishSend(receiver, arguments, charOffset); | 351 return helper.finishSend(receiver, arguments, charOffset); |
350 } | 352 } |
351 Expression result; | 353 Expression result; |
352 if (receiver is KernelClassBuilder) { | 354 if (receiver is KernelClassBuilder) { |
353 Builder builder = receiver.findStaticBuilder(name.name, charOffset, uri); | 355 Builder builder = receiver.findStaticBuilder(name.name, charOffset, uri); |
354 if (builder == null) { | 356 if (builder == null) { |
355 return buildThrowNoSuchMethodError(arguments); | 357 return buildThrowNoSuchMethodError(arguments); |
356 } | 358 } |
357 if (builder.hasProblem) { | 359 if (builder.hasProblem) { |
358 result = helper.buildProblemExpression(builder, charOffset); | 360 result = |
| 361 helper.buildProblemExpression(builder, charOffset) as Expression; |
359 } else { | 362 } else { |
360 Member target = builder.target; | 363 Member target = builder.target; |
361 if (target != null) { | 364 if (target != null) { |
362 if (target is Field) { | 365 if (target is Field) { |
363 result = buildMethodInvocation(new StaticGet(target), callName, | 366 result = buildMethodInvocation(new StaticGet(target), callName, |
364 arguments, charOffset + (target.name?.name?.length ?? 0), | 367 arguments, charOffset + (target.name?.name?.length ?? 0), |
365 isNullAware: isNullAware); | 368 isNullAware: isNullAware); |
366 } else { | 369 } else { |
367 result = helper.buildStaticInvocation(target, arguments) | 370 result = helper.buildStaticInvocation(target, arguments) |
368 ..fileOffset = charOffset; | 371 ..fileOffset = charOffset; |
369 } | 372 } |
370 } else { | 373 } else { |
371 result = buildThrowNoSuchMethodError(arguments) | 374 result = buildThrowNoSuchMethodError(arguments) |
372 ..fileOffset = charOffset; | 375 ..fileOffset = charOffset; |
373 } | 376 } |
374 } | 377 } |
375 } else { | 378 } else { |
376 result = buildMethodInvocation( | 379 result = buildMethodInvocation( |
377 helper.toValue(receiver), name, arguments, charOffset, | 380 helper.toValue(receiver) as Expression, name, arguments, charOffset, |
378 isNullAware: isNullAware); | 381 isNullAware: isNullAware); |
379 } | 382 } |
380 return result; | 383 return result; |
381 } | 384 } |
382 | 385 |
383 Expression buildNullAwareAssignment(Expression value, DartType type, | 386 Expression buildNullAwareAssignment(Expression value, DartType type, |
384 {bool voidContext: false}) { | 387 {bool voidContext: false}) { |
385 return internalError("Unhandled"); | 388 return internalError("Unhandled"); |
386 } | 389 } |
387 | 390 |
(...skipping 19 matching lines...) Expand all Loading... |
407 | 410 |
408 toString() => "SendAccessor($charOffset, $name, $arguments)"; | 411 toString() => "SendAccessor($charOffset, $name, $arguments)"; |
409 } | 412 } |
410 | 413 |
411 class IncompletePropertyAccessor extends IncompleteSend { | 414 class IncompletePropertyAccessor extends IncompleteSend { |
412 IncompletePropertyAccessor(BuilderHelper helper, int charOffset, Name name) | 415 IncompletePropertyAccessor(BuilderHelper helper, int charOffset, Name name) |
413 : super(helper, charOffset, name); | 416 : super(helper, charOffset, name); |
414 | 417 |
415 String get plainNameForRead => name.name; | 418 String get plainNameForRead => name.name; |
416 | 419 |
417 Expression buildSimpleRead() => internalError("Unhandled"); | 420 ShadowExpression buildSimpleRead() => internalError("Unhandled"); |
418 | 421 |
419 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 422 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
420 return internalError("Unhandled"); | 423 return internalError("Unhandled"); |
421 } | 424 } |
422 | 425 |
423 withReceiver(Object receiver, {bool isNullAware: false}) { | 426 withReceiver(Object receiver, {bool isNullAware: false}) { |
424 if (receiver is TypeDeclarationBuilder) { | 427 if (receiver is TypeDeclarationBuilder) { |
425 /// For reasons beyond comprehension, `SomeType?.toString` is the same as | 428 /// For reasons beyond comprehension, `SomeType?.toString` is the same as |
426 /// `SomeType.toString`, not `(SomeType).toString`. WTAF!?! | 429 /// `SomeType.toString`, not `(SomeType).toString`. WTAF!?! |
427 // | 430 // |
(...skipping 19 matching lines...) Expand all Loading... |
447 setter = builder; | 450 setter = builder; |
448 } else if (builder.isGetter) { | 451 } else if (builder.isGetter) { |
449 setter = receiver.findStaticBuilder(name.name, charOffset, uri, | 452 setter = receiver.findStaticBuilder(name.name, charOffset, uri, |
450 isSetter: true); | 453 isSetter: true); |
451 } else if (builder.isField && !builder.isFinal) { | 454 } else if (builder.isField && !builder.isFinal) { |
452 setter = builder; | 455 setter = builder; |
453 } | 456 } |
454 return new StaticAccessor.fromBuilder( | 457 return new StaticAccessor.fromBuilder( |
455 helper, builder, charOffset, setter); | 458 helper, builder, charOffset, setter); |
456 } | 459 } |
457 return PropertyAccessor.make(helper, charOffset, helper.toValue(receiver), | 460 return PropertyAccessor.make(helper, charOffset, |
458 name, null, null, isNullAware); | 461 helper.toValue(receiver) as Expression, name, null, null, isNullAware); |
459 } | 462 } |
460 | 463 |
461 Expression buildNullAwareAssignment(Expression value, DartType type, | 464 Expression buildNullAwareAssignment(Expression value, DartType type, |
462 {bool voidContext: false}) { | 465 {bool voidContext: false}) { |
463 return internalError("Unhandled"); | 466 return internalError("Unhandled"); |
464 } | 467 } |
465 | 468 |
466 Expression buildCompoundAssignment( | 469 Expression buildCompoundAssignment( |
467 Name binaryOperator, Expression value, int charOffset, | 470 Name binaryOperator, Expression value, int charOffset, |
468 {bool voidContext: false, Procedure interfaceTarget}) { | 471 {bool voidContext: false, Procedure interfaceTarget}) { |
(...skipping 23 matching lines...) Expand all Loading... |
492 IndexAccessor.internal(this.helper, int charOffset, Expression receiver, | 495 IndexAccessor.internal(this.helper, int charOffset, Expression receiver, |
493 Expression index, Procedure getter, Procedure setter) | 496 Expression index, Procedure getter, Procedure setter) |
494 : super.internal(receiver, index, getter, setter, charOffset); | 497 : super.internal(receiver, index, getter, setter, charOffset); |
495 | 498 |
496 String get plainNameForRead => "[]"; | 499 String get plainNameForRead => "[]"; |
497 | 500 |
498 String get plainNameForWrite => "[]="; | 501 String get plainNameForWrite => "[]="; |
499 | 502 |
500 Expression doInvocation(int charOffset, Arguments arguments) { | 503 Expression doInvocation(int charOffset, Arguments arguments) { |
501 return buildMethodInvocation( | 504 return buildMethodInvocation( |
502 buildSimpleRead(), callName, arguments, charOffset); | 505 buildSimpleRead() as Expression, callName, arguments, charOffset); |
503 } | 506 } |
504 | 507 |
505 toString() => "IndexAccessor()"; | 508 toString() => "IndexAccessor()"; |
506 | 509 |
507 static BuilderAccessor make( | 510 static BuilderAccessor make( |
508 BuilderHelper helper, | 511 BuilderHelper helper, |
509 int charOffset, | 512 int charOffset, |
510 Expression receiver, | 513 Expression receiver, |
511 Expression index, | 514 Expression index, |
512 Procedure getter, | 515 Procedure getter, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 setter = builderSetter.target; | 587 setter = builderSetter.target; |
585 } | 588 } |
586 } | 589 } |
587 return new StaticAccessor(helper, charOffset, getter, setter); | 590 return new StaticAccessor(helper, charOffset, getter, setter); |
588 } | 591 } |
589 | 592 |
590 String get plainNameForRead => (readTarget ?? writeTarget).name.name; | 593 String get plainNameForRead => (readTarget ?? writeTarget).name.name; |
591 | 594 |
592 Expression doInvocation(int charOffset, Arguments arguments) { | 595 Expression doInvocation(int charOffset, Arguments arguments) { |
593 if (readTarget == null || isFieldOrGetter(readTarget)) { | 596 if (readTarget == null || isFieldOrGetter(readTarget)) { |
594 return buildMethodInvocation(buildSimpleRead(), callName, arguments, | 597 return buildMethodInvocation(buildSimpleRead() as Expression, callName, |
595 charOffset + (readTarget?.name?.name?.length ?? 0)); | 598 arguments, charOffset + (readTarget?.name?.name?.length ?? 0)); |
596 } else { | 599 } else { |
597 return helper.buildStaticInvocation(readTarget, arguments) | 600 return helper.buildStaticInvocation(readTarget, arguments) |
598 ..fileOffset = charOffset; | 601 ..fileOffset = charOffset; |
599 } | 602 } |
600 } | 603 } |
601 | 604 |
602 toString() => "StaticAccessor()"; | 605 toString() => "StaticAccessor()"; |
603 } | 606 } |
604 | 607 |
605 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor | 608 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor |
606 with BuilderAccessor { | 609 with BuilderAccessor { |
607 final BuilderHelper helper; | 610 final BuilderHelper helper; |
608 | 611 |
609 SuperPropertyAccessor( | 612 SuperPropertyAccessor( |
610 this.helper, int charOffset, Name name, Member getter, Member setter) | 613 this.helper, int charOffset, Name name, Member getter, Member setter) |
611 : super(name, getter, setter, charOffset); | 614 : super(name, getter, setter, charOffset); |
612 | 615 |
613 String get plainNameForRead => name.name; | 616 String get plainNameForRead => name.name; |
614 | 617 |
615 Expression doInvocation(int charOffset, Arguments arguments) { | 618 Expression doInvocation(int charOffset, Arguments arguments) { |
616 if (getter == null || isFieldOrGetter(getter)) { | 619 if (getter == null || isFieldOrGetter(getter)) { |
617 return buildMethodInvocation( | 620 return buildMethodInvocation( |
618 buildSimpleRead(), callName, arguments, charOffset); | 621 buildSimpleRead() as Expression, callName, arguments, charOffset); |
619 } else { | 622 } else { |
620 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) | 623 return new DirectMethodInvocation(new ThisExpression(), getter, arguments) |
621 ..fileOffset = charOffset; | 624 ..fileOffset = charOffset; |
622 } | 625 } |
623 } | 626 } |
624 | 627 |
625 toString() => "SuperPropertyAccessor()"; | 628 toString() => "SuperPropertyAccessor()"; |
626 } | 629 } |
627 | 630 |
628 class ThisIndexAccessor extends kernel.ThisIndexAccessor with BuilderAccessor { | 631 class ThisIndexAccessor extends kernel.ThisIndexAccessor with BuilderAccessor { |
629 final BuilderHelper helper; | 632 final BuilderHelper helper; |
630 | 633 |
631 final int charOffset; | 634 final int charOffset; |
632 | 635 |
633 ThisIndexAccessor(this.helper, this.charOffset, Expression index, | 636 ThisIndexAccessor(this.helper, this.charOffset, Expression index, |
634 Procedure getter, Procedure setter) | 637 Procedure getter, Procedure setter) |
635 : super(index, getter, setter); | 638 : super(index, getter, setter); |
636 | 639 |
637 String get plainNameForRead => "[]"; | 640 String get plainNameForRead => "[]"; |
638 | 641 |
639 String get plainNameForWrite => "[]="; | 642 String get plainNameForWrite => "[]="; |
640 | 643 |
641 Expression doInvocation(int charOffset, Arguments arguments) { | 644 Expression doInvocation(int charOffset, Arguments arguments) { |
642 return buildMethodInvocation( | 645 return buildMethodInvocation( |
643 buildSimpleRead(), callName, arguments, charOffset); | 646 buildSimpleRead() as Expression, callName, arguments, charOffset); |
644 } | 647 } |
645 | 648 |
646 toString() => "ThisIndexAccessor()"; | 649 toString() => "ThisIndexAccessor()"; |
647 } | 650 } |
648 | 651 |
649 class SuperIndexAccessor extends kernel.SuperIndexAccessor | 652 class SuperIndexAccessor extends kernel.SuperIndexAccessor |
650 with BuilderAccessor { | 653 with BuilderAccessor { |
651 final BuilderHelper helper; | 654 final BuilderHelper helper; |
652 | 655 |
653 final int charOffset; | 656 final int charOffset; |
654 | 657 |
655 SuperIndexAccessor(this.helper, this.charOffset, Expression index, | 658 SuperIndexAccessor(this.helper, this.charOffset, Expression index, |
656 Member getter, Member setter) | 659 Member getter, Member setter) |
657 : super(index, getter, setter); | 660 : super(index, getter, setter); |
658 | 661 |
659 String get plainNameForRead => "[]"; | 662 String get plainNameForRead => "[]"; |
660 | 663 |
661 String get plainNameForWrite => "[]="; | 664 String get plainNameForWrite => "[]="; |
662 | 665 |
663 Expression doInvocation(int charOffset, Arguments arguments) { | 666 Expression doInvocation(int charOffset, Arguments arguments) { |
664 return buildMethodInvocation( | 667 return buildMethodInvocation( |
665 buildSimpleRead(), callName, arguments, charOffset); | 668 buildSimpleRead() as Expression, callName, arguments, charOffset); |
666 } | 669 } |
667 | 670 |
668 toString() => "SuperIndexAccessor()"; | 671 toString() => "SuperIndexAccessor()"; |
669 } | 672 } |
670 | 673 |
671 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor | 674 class ThisPropertyAccessor extends kernel.ThisPropertyAccessor |
672 with BuilderAccessor { | 675 with BuilderAccessor { |
673 final BuilderHelper helper; | 676 final BuilderHelper helper; |
674 | 677 |
675 ThisPropertyAccessor( | 678 ThisPropertyAccessor( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 | 721 |
719 VariableAccessor(this.helper, int charOffset, VariableDeclaration variable, | 722 VariableAccessor(this.helper, int charOffset, VariableDeclaration variable, |
720 [DartType promotedType]) | 723 [DartType promotedType]) |
721 : super.internal(variable, charOffset, promotedType); | 724 : super.internal(variable, charOffset, promotedType); |
722 | 725 |
723 String get plainNameForRead => variable.name; | 726 String get plainNameForRead => variable.name; |
724 | 727 |
725 Expression doInvocation(int charOffset, Arguments arguments) { | 728 Expression doInvocation(int charOffset, Arguments arguments) { |
726 // Normally the offset is at the start of the token, but in this case, | 729 // Normally the offset is at the start of the token, but in this case, |
727 // because we insert a '.call', we want it at the end instead. | 730 // because we insert a '.call', we want it at the end instead. |
728 return buildMethodInvocation(buildSimpleRead(), callName, arguments, | 731 return buildMethodInvocation(buildSimpleRead() as Expression, callName, |
729 charOffset + (variable.name?.length ?? 0)); | 732 arguments, charOffset + (variable.name?.length ?? 0)); |
730 } | 733 } |
731 | 734 |
732 toString() => "VariableAccessor()"; | 735 toString() => "VariableAccessor()"; |
733 } | 736 } |
734 | 737 |
735 bool isFieldOrGetter(Member member) { | 738 bool isFieldOrGetter(Member member) { |
736 return member is Field || (member is Procedure && member.isGetter); | 739 return member is Field || (member is Procedure && member.isGetter); |
737 } | 740 } |
738 | 741 |
739 Expression buildMethodInvocation( | 742 Expression buildMethodInvocation( |
740 Expression receiver, Name name, Arguments arguments, int charOffset, | 743 Expression receiver, Name name, Arguments arguments, int charOffset, |
741 {bool isNullAware: false}) { | 744 {bool isNullAware: false}) { |
742 if (isNullAware) { | 745 if (isNullAware) { |
743 VariableDeclaration variable = new VariableDeclaration.forValue(receiver); | 746 VariableDeclaration variable = new VariableDeclaration.forValue(receiver); |
744 return makeLet( | 747 return makeLet( |
745 variable, | 748 variable, |
746 new ConditionalExpression( | 749 new ConditionalExpression( |
747 buildIsNull(new VariableGet(variable)), | 750 buildIsNull(new VariableGet(variable)), |
748 new NullLiteral(), | 751 new NullLiteral(), |
749 new MethodInvocation(new VariableGet(variable), name, arguments) | 752 new MethodInvocation(new VariableGet(variable), name, arguments) |
750 ..fileOffset = charOffset, | 753 ..fileOffset = charOffset, |
751 const DynamicType())); | 754 const DynamicType())); |
752 } else { | 755 } else { |
753 return new MethodInvocation(receiver, name, arguments) | 756 return new MethodInvocation(receiver, name, arguments) |
754 ..fileOffset = charOffset; | 757 ..fileOffset = charOffset; |
755 } | 758 } |
756 } | 759 } |
OLD | NEW |