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.fasta_accessors; | 5 library fasta.fasta_accessors; |
6 | 6 |
7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
8 show | 8 show |
9 KernelArguments, | 9 KernelArguments, |
10 KernelComplexAssignment, | 10 KernelComplexAssignment, |
11 KernelIndexAssign, | 11 KernelIndexAssign, |
12 KernelPropertyAssign, | 12 KernelPropertyAssign, |
13 KernelStaticAssignment, | 13 KernelStaticAssignment, |
14 KernelThisExpression, | 14 KernelThisExpression, |
15 KernelTypeLiteral, | 15 KernelTypeLiteral, |
16 KernelVariableAssignment; | 16 KernelVariableAssignment; |
17 | 17 |
18 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 18 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
19 | 19 |
20 import 'package:front_end/src/scanner/token.dart' show Token; | 20 import 'package:front_end/src/scanner/token.dart' show Token; |
21 | 21 |
22 import 'frontend_accessors.dart' show Accessor; | 22 import 'frontend_accessors.dart' show Accessor; |
23 | 23 |
24 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' | 24 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' |
25 show TypePromoter; | 25 show TypePromoter; |
26 | 26 |
27 import 'package:kernel/ast.dart' | 27 import 'package:kernel/ast.dart' |
28 hide InvalidExpression, InvalidInitializer, InvalidStatement; | 28 hide InvalidExpression, InvalidInitializer, InvalidStatement; |
29 | 29 |
30 import '../errors.dart' show internalError; | 30 import '../deprecated_problems.dart' show deprecated_internalProblem; |
31 | 31 |
32 import '../scope.dart' show AccessErrorBuilder, ProblemBuilder, Scope; | 32 import '../scope.dart' |
| 33 show deprecated_AccessErrorBuilder, ProblemBuilder, Scope; |
33 | 34 |
34 import 'frontend_accessors.dart' as kernel | 35 import 'frontend_accessors.dart' as kernel |
35 show | 36 show |
36 IndexAccessor, | 37 IndexAccessor, |
37 NullAwarePropertyAccessor, | 38 NullAwarePropertyAccessor, |
38 PropertyAccessor, | 39 PropertyAccessor, |
39 ReadOnlyAccessor, | 40 ReadOnlyAccessor, |
40 StaticAccessor, | 41 StaticAccessor, |
41 SuperIndexAccessor, | 42 SuperIndexAccessor, |
42 SuperPropertyAccessor, | 43 SuperPropertyAccessor, |
(...skipping 29 matching lines...) Expand all Loading... |
72 | 73 |
73 Expression toValue(node); | 74 Expression toValue(node); |
74 | 75 |
75 Member lookupSuperMember(Name name, {bool isSetter}); | 76 Member lookupSuperMember(Name name, {bool isSetter}); |
76 | 77 |
77 scopeLookup(Scope scope, String name, Token token, | 78 scopeLookup(Scope scope, String name, Token token, |
78 {bool isQualified: false, PrefixBuilder prefix}); | 79 {bool isQualified: false, PrefixBuilder prefix}); |
79 | 80 |
80 finishSend(Object receiver, Arguments arguments, int offset); | 81 finishSend(Object receiver, Arguments arguments, int offset); |
81 | 82 |
82 Expression buildCompileTimeError(error, [int offset]); | 83 Expression deprecated_buildCompileTimeError(error, [int offset]); |
83 | 84 |
84 Initializer buildInvalidInitializer(Expression expression, [int offset]); | 85 Initializer buildInvalidInitializer(Expression expression, [int offset]); |
85 | 86 |
86 Initializer buildFieldInitializer( | 87 Initializer buildFieldInitializer( |
87 String name, int offset, Expression expression); | 88 String name, int offset, Expression expression); |
88 | 89 |
89 Initializer buildSuperInitializer( | 90 Initializer buildSuperInitializer( |
90 Constructor constructor, Arguments arguments, | 91 Constructor constructor, Arguments arguments, |
91 [int offset]); | 92 [int offset]); |
92 | 93 |
93 Initializer buildRedirectingInitializer( | 94 Initializer buildRedirectingInitializer( |
94 Constructor constructor, Arguments arguments, | 95 Constructor constructor, Arguments arguments, |
95 [int charOffset = -1]); | 96 [int charOffset = -1]); |
96 | 97 |
97 Expression buildStaticInvocation(Procedure target, Arguments arguments); | 98 Expression buildStaticInvocation(Procedure target, Arguments arguments); |
98 | 99 |
99 Expression buildProblemExpression(ProblemBuilder builder, int offset); | 100 Expression buildProblemExpression(ProblemBuilder builder, int offset); |
100 | 101 |
101 Expression throwNoSuchMethodError( | 102 Expression throwNoSuchMethodError( |
102 Expression receiver, String name, Arguments arguments, int offset, | 103 Expression receiver, String name, Arguments arguments, int offset, |
103 {bool isSuper, bool isGetter, bool isSetter, bool isStatic}); | 104 {bool isSuper, bool isGetter, bool isSetter, bool isStatic}); |
104 | 105 |
105 bool checkArguments(FunctionNode function, Arguments arguments, | 106 bool checkArguments(FunctionNode function, Arguments arguments, |
106 List<TypeParameter> typeParameters); | 107 List<TypeParameter> typeParameters); |
107 | 108 |
108 StaticGet makeStaticGet(Member readTarget, Token token); | 109 StaticGet makeStaticGet(Member readTarget, Token token); |
109 | 110 |
110 dynamic addCompileTimeError(int charOffset, String message, {bool silent}); | 111 dynamic deprecated_addCompileTimeError(int charOffset, String message, |
| 112 {bool silent}); |
111 | 113 |
112 bool isIdentical(Member member); | 114 bool isIdentical(Member member); |
113 | 115 |
114 Expression buildMethodInvocation( | 116 Expression buildMethodInvocation( |
115 Expression receiver, Name name, Arguments arguments, int offset, | 117 Expression receiver, Name name, Arguments arguments, int offset, |
116 {bool isConstantExpression, bool isNullAware, bool isImplicitCall}); | 118 {bool isConstantExpression, bool isNullAware, bool isImplicitCall}); |
117 | 119 |
118 DartType validatedTypeVariableUse( | 120 DartType validatedTypeVariableUse( |
119 TypeParameterType type, int offset, bool nonInstanceAccessIsError); | 121 TypeParameterType type, int offset, bool nonInstanceAccessIsError); |
120 | 122 |
121 void warning(String message, [int charOffset]); | 123 void deprecated_warning(String message, [int charOffset]); |
122 | 124 |
123 void warnUnresolvedSuperGet(Name name, int charOffset); | 125 void warnUnresolvedSuperGet(Name name, int charOffset); |
124 | 126 |
125 void warnUnresolvedSuperSet(Name name, int charOffset); | 127 void warnUnresolvedSuperSet(Name name, int charOffset); |
126 | 128 |
127 void warnUnresolvedSuperMethod(Name name, int charOffset); | 129 void warnUnresolvedSuperMethod(Name name, int charOffset); |
128 } | 130 } |
129 | 131 |
130 abstract class FastaAccessor implements Accessor { | 132 abstract class FastaAccessor implements Accessor { |
131 BuilderHelper get helper; | 133 BuilderHelper get helper; |
132 | 134 |
133 String get plainNameForRead; | 135 String get plainNameForRead; |
134 | 136 |
135 Uri get uri => helper.uri; | 137 Uri get uri => helper.uri; |
136 | 138 |
137 String get plainNameForWrite => plainNameForRead; | 139 String get plainNameForWrite => plainNameForRead; |
138 | 140 |
139 bool get isInitializer => false; | 141 bool get isInitializer => false; |
140 | 142 |
141 Expression buildForEffect() => buildSimpleRead(); | 143 Expression buildForEffect() => buildSimpleRead(); |
142 | 144 |
143 Initializer buildFieldInitializer(Map<String, int> initializedFields) { | 145 Initializer buildFieldInitializer(Map<String, int> initializedFields) { |
144 int offset = offsetForToken(token); | 146 int offset = offsetForToken(token); |
145 return helper.buildInvalidInitializer( | 147 return helper.buildInvalidInitializer( |
146 helper.buildCompileTimeError( | 148 helper.deprecated_buildCompileTimeError( |
147 // TODO(ahe): This error message is really bad. | 149 // TODO(ahe): This error message is really bad. |
148 "Can't use $plainNameForRead here.", | 150 "Can't use $plainNameForRead here.", |
149 offset), | 151 offset), |
150 offset); | 152 offset); |
151 } | 153 } |
152 | 154 |
153 Expression makeInvalidRead() { | 155 Expression makeInvalidRead() { |
154 return buildThrowNoSuchMethodError( | 156 return buildThrowNoSuchMethodError( |
155 new NullLiteral()..fileOffset = offsetForToken(token), | 157 new NullLiteral()..fileOffset = offsetForToken(token), |
156 new Arguments.empty(), | 158 new Arguments.empty(), |
(...skipping 11 matching lines...) Expand all Loading... |
168 int offset, Arguments arguments); | 170 int offset, Arguments arguments); |
169 | 171 |
170 /* Expression | FastaAccessor */ buildPropertyAccess( | 172 /* Expression | FastaAccessor */ buildPropertyAccess( |
171 IncompleteSend send, int operatorOffset, bool isNullAware) { | 173 IncompleteSend send, int operatorOffset, bool isNullAware) { |
172 if (send is SendAccessor) { | 174 if (send is SendAccessor) { |
173 return helper.buildMethodInvocation(buildSimpleRead(), send.name, | 175 return helper.buildMethodInvocation(buildSimpleRead(), send.name, |
174 send.arguments, offsetForToken(send.token), | 176 send.arguments, offsetForToken(send.token), |
175 isNullAware: isNullAware); | 177 isNullAware: isNullAware); |
176 } else { | 178 } else { |
177 if (helper.constantExpressionRequired && send.name != lengthName) { | 179 if (helper.constantExpressionRequired && send.name != lengthName) { |
178 helper.addCompileTimeError( | 180 helper.deprecated_addCompileTimeError( |
179 offsetForToken(token), "Not a constant expression."); | 181 offsetForToken(token), "Not a constant expression."); |
180 } | 182 } |
181 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), | 183 return PropertyAccessor.make(helper, send.token, buildSimpleRead(), |
182 send.name, null, null, isNullAware); | 184 send.name, null, null, isNullAware); |
183 } | 185 } |
184 } | 186 } |
185 | 187 |
186 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError( | 188 /* Expression | FastaAccessor */ buildThrowNoSuchMethodError( |
187 Expression receiver, Arguments arguments, | 189 Expression receiver, Arguments arguments, |
188 {bool isSuper: false, | 190 {bool isSuper: false, |
(...skipping 16 matching lines...) Expand all Loading... |
205 KernelComplexAssignment startComplexAssignment(Expression rhs) => null; | 207 KernelComplexAssignment startComplexAssignment(Expression rhs) => null; |
206 } | 208 } |
207 | 209 |
208 abstract class ErrorAccessor implements FastaAccessor { | 210 abstract class ErrorAccessor implements FastaAccessor { |
209 /// Pass [arguments] that must be evaluated before throwing an error. At | 211 /// Pass [arguments] that must be evaluated before throwing an error. At |
210 /// most one of [isGetter] and [isSetter] should be true and they're passed | 212 /// most one of [isGetter] and [isSetter] should be true and they're passed |
211 /// to [BuilderHelper.buildThrowNoSuchMethodError] if it is used. | 213 /// to [BuilderHelper.buildThrowNoSuchMethodError] if it is used. |
212 Expression buildError(Arguments arguments, | 214 Expression buildError(Arguments arguments, |
213 {bool isGetter: false, bool isSetter: false, int offset}); | 215 {bool isGetter: false, bool isSetter: false, int offset}); |
214 | 216 |
215 Name get name => internalError("Unsupported operation."); | 217 Name get name => deprecated_internalProblem("Unsupported operation."); |
216 | 218 |
217 @override | 219 @override |
218 String get plainNameForRead => name.name; | 220 String get plainNameForRead => name.name; |
219 | 221 |
220 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}) => this; | 222 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}) => this; |
221 | 223 |
222 @override | 224 @override |
223 Initializer buildFieldInitializer(Map<String, int> initializedFields) { | 225 Initializer buildFieldInitializer(Map<String, int> initializedFields) { |
224 return helper.buildInvalidInitializer( | 226 return helper.buildInvalidInitializer( |
225 buildError(new Arguments.empty(), isSetter: true)); | 227 buildError(new Arguments.empty(), isSetter: true)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 307 |
306 final Token token; | 308 final Token token; |
307 | 309 |
308 final bool isInitializer; | 310 final bool isInitializer; |
309 | 311 |
310 final bool isSuper; | 312 final bool isSuper; |
311 | 313 |
312 ThisAccessor(this.helper, this.token, this.isInitializer, | 314 ThisAccessor(this.helper, this.token, this.isInitializer, |
313 {this.isSuper: false}); | 315 {this.isSuper: false}); |
314 | 316 |
315 String get plainNameForRead => internalError(isSuper ? "super" : "this"); | 317 String get plainNameForRead => |
| 318 deprecated_internalProblem(isSuper ? "super" : "this"); |
316 | 319 |
317 Expression buildSimpleRead() { | 320 Expression buildSimpleRead() { |
318 if (!isSuper) { | 321 if (!isSuper) { |
319 return new KernelThisExpression(); | 322 return new KernelThisExpression(); |
320 } else { | 323 } else { |
321 return helper.buildCompileTimeError( | 324 return helper.deprecated_buildCompileTimeError( |
322 "Can't use `super` as an expression.", offsetForToken(token)); | 325 "Can't use `super` as an expression.", offsetForToken(token)); |
323 } | 326 } |
324 } | 327 } |
325 | 328 |
326 @override | 329 @override |
327 Initializer buildFieldInitializer(Map<String, int> initializedFields) { | 330 Initializer buildFieldInitializer(Map<String, int> initializedFields) { |
328 String keyword = isSuper ? "super" : "this"; | 331 String keyword = isSuper ? "super" : "this"; |
329 int offset = offsetForToken(token); | 332 int offset = offsetForToken(token); |
330 return helper.buildInvalidInitializer( | 333 return helper.buildInvalidInitializer( |
331 helper.buildCompileTimeError( | 334 helper.deprecated_buildCompileTimeError( |
332 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), | 335 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), |
333 offset); | 336 offset); |
334 } | 337 } |
335 | 338 |
336 buildPropertyAccess( | 339 buildPropertyAccess( |
337 IncompleteSend send, int operatorOffset, bool isNullAware) { | 340 IncompleteSend send, int operatorOffset, bool isNullAware) { |
338 if (isInitializer && send is SendAccessor) { | 341 if (isInitializer && send is SendAccessor) { |
339 if (isNullAware) { | 342 if (isNullAware) { |
340 helper.addCompileTimeError( | 343 helper.deprecated_addCompileTimeError( |
341 operatorOffset, "Expected '.'\nTry removing '?'."); | 344 operatorOffset, "Expected '.'\nTry removing '?'."); |
342 } | 345 } |
343 return buildConstructorInitializer( | 346 return buildConstructorInitializer( |
344 offsetForToken(send.token), send.name, send.arguments); | 347 offsetForToken(send.token), send.name, send.arguments); |
345 } | 348 } |
346 if (send is SendAccessor) { | 349 if (send is SendAccessor) { |
347 // Notice that 'this' or 'super' can't be null. So we can ignore the | 350 // Notice that 'this' or 'super' can't be null. So we can ignore the |
348 // value of [isNullAware]. | 351 // value of [isNullAware]. |
349 MethodInvocation result = helper.buildMethodInvocation( | 352 MethodInvocation result = helper.buildMethodInvocation( |
350 new KernelThisExpression(), | 353 new KernelThisExpression(), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 Expression buildPostfixIncrement(Name binaryOperator, | 424 Expression buildPostfixIncrement(Name binaryOperator, |
422 {int offset: TreeNode.noOffset, | 425 {int offset: TreeNode.noOffset, |
423 bool voidContext: false, | 426 bool voidContext: false, |
424 Procedure interfaceTarget}) { | 427 Procedure interfaceTarget}) { |
425 return buildAssignmentError(); | 428 return buildAssignmentError(); |
426 } | 429 } |
427 | 430 |
428 Expression buildAssignmentError() { | 431 Expression buildAssignmentError() { |
429 String message = | 432 String message = |
430 isSuper ? "Can't assign to 'super'." : "Can't assign to 'this'."; | 433 isSuper ? "Can't assign to 'super'." : "Can't assign to 'this'."; |
431 return helper.buildCompileTimeError(message, offsetForToken(token)); | 434 return helper.deprecated_buildCompileTimeError( |
| 435 message, offsetForToken(token)); |
432 } | 436 } |
433 | 437 |
434 toString() { | 438 toString() { |
435 int offset = offsetForToken(token); | 439 int offset = offsetForToken(token); |
436 return "ThisAccessor($offset${isSuper ? ', super' : ''})"; | 440 return "ThisAccessor($offset${isSuper ? ', super' : ''})"; |
437 } | 441 } |
438 } | 442 } |
439 | 443 |
440 abstract class IncompleteSend extends FastaAccessor { | 444 abstract class IncompleteSend extends FastaAccessor { |
441 final BuilderHelper helper; | 445 final BuilderHelper helper; |
442 | 446 |
443 @override | 447 @override |
444 final Token token; | 448 final Token token; |
445 | 449 |
446 final Name name; | 450 final Name name; |
447 | 451 |
448 IncompleteSend(this.helper, this.token, this.name); | 452 IncompleteSend(this.helper, this.token, this.name); |
449 | 453 |
450 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}); | 454 withReceiver(Object receiver, int operatorOffset, {bool isNullAware}); |
451 | 455 |
452 Arguments get arguments => null; | 456 Arguments get arguments => null; |
453 } | 457 } |
454 | 458 |
455 class IncompleteError extends IncompleteSend with ErrorAccessor { | 459 class deprecated_IncompleteError extends IncompleteSend with ErrorAccessor { |
456 final Object error; | 460 final Object error; |
457 | 461 |
458 IncompleteError(BuilderHelper helper, Token token, this.error) | 462 deprecated_IncompleteError(BuilderHelper helper, Token token, this.error) |
459 : super(helper, token, null); | 463 : super(helper, token, null); |
460 | 464 |
461 @override | 465 @override |
462 Expression buildError(Arguments arguments, | 466 Expression buildError(Arguments arguments, |
463 {bool isGetter: false, bool isSetter: false, int offset}) { | 467 {bool isGetter: false, bool isSetter: false, int offset}) { |
464 return helper.buildCompileTimeError( | 468 return helper.deprecated_buildCompileTimeError( |
465 error, offset ?? offsetForToken(this.token)); | 469 error, offset ?? offsetForToken(this.token)); |
466 } | 470 } |
467 | 471 |
468 @override | 472 @override |
469 doInvocation(int offset, Arguments arguments) => this; | 473 doInvocation(int offset, Arguments arguments) => this; |
470 } | 474 } |
471 | 475 |
472 class SendAccessor extends IncompleteSend { | 476 class SendAccessor extends IncompleteSend { |
473 @override | 477 @override |
474 final Arguments arguments; | 478 final Arguments arguments; |
475 | 479 |
476 SendAccessor(BuilderHelper helper, Token token, Name name, this.arguments) | 480 SendAccessor(BuilderHelper helper, Token token, Name name, this.arguments) |
477 : super(helper, token, name) { | 481 : super(helper, token, name) { |
478 assert(arguments != null); | 482 assert(arguments != null); |
479 } | 483 } |
480 | 484 |
481 String get plainNameForRead => name.name; | 485 String get plainNameForRead => name.name; |
482 | 486 |
483 Expression buildSimpleRead() { | 487 Expression buildSimpleRead() { |
484 return internalError("Unhandled"); | 488 return deprecated_internalProblem("Unhandled"); |
485 } | 489 } |
486 | 490 |
487 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 491 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
488 return internalError("Unhandled"); | 492 return deprecated_internalProblem("Unhandled"); |
489 } | 493 } |
490 | 494 |
491 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { | 495 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { |
492 if (receiver is FastaAccessor) { | 496 if (receiver is FastaAccessor) { |
493 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); | 497 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); |
494 } | 498 } |
495 if (receiver is PrefixBuilder) { | 499 if (receiver is PrefixBuilder) { |
496 PrefixBuilder prefix = receiver; | 500 PrefixBuilder prefix = receiver; |
497 if (isNullAware) { | 501 if (isNullAware) { |
498 helper.addCompileTimeError( | 502 helper.deprecated_addCompileTimeError( |
499 offsetForToken(token), | 503 offsetForToken(token), |
500 "Library prefix '${prefix.name}' can't be used with null-aware " | 504 "Library prefix '${prefix.name}' can't be used with null-aware " |
501 "operator.\nTry removing '?'."); | 505 "operator.\nTry removing '?'."); |
502 } | 506 } |
503 receiver = helper.scopeLookup(prefix.exports, name.name, token, | 507 receiver = helper.scopeLookup(prefix.exports, name.name, token, |
504 isQualified: true, prefix: prefix); | 508 isQualified: true, prefix: prefix); |
505 return helper.finishSend(receiver, arguments, offsetForToken(token)); | 509 return helper.finishSend(receiver, arguments, offsetForToken(token)); |
506 } | 510 } |
507 return helper.buildMethodInvocation( | 511 return helper.buildMethodInvocation( |
508 helper.toValue(receiver), name, arguments, offsetForToken(token), | 512 helper.toValue(receiver), name, arguments, offsetForToken(token), |
509 isNullAware: isNullAware); | 513 isNullAware: isNullAware); |
510 } | 514 } |
511 | 515 |
512 Expression buildNullAwareAssignment( | 516 Expression buildNullAwareAssignment( |
513 Expression value, DartType type, int offset, | 517 Expression value, DartType type, int offset, |
514 {bool voidContext: false}) { | 518 {bool voidContext: false}) { |
515 return internalError("Unhandled"); | 519 return deprecated_internalProblem("Unhandled"); |
516 } | 520 } |
517 | 521 |
518 Expression buildCompoundAssignment(Name binaryOperator, Expression value, | 522 Expression buildCompoundAssignment(Name binaryOperator, Expression value, |
519 {int offset, | 523 {int offset, |
520 bool voidContext: false, | 524 bool voidContext: false, |
521 Procedure interfaceTarget, | 525 Procedure interfaceTarget, |
522 bool isPreIncDec: false}) { | 526 bool isPreIncDec: false}) { |
523 return internalError("Unhandled"); | 527 return deprecated_internalProblem("Unhandled"); |
524 } | 528 } |
525 | 529 |
526 Expression buildPrefixIncrement(Name binaryOperator, | 530 Expression buildPrefixIncrement(Name binaryOperator, |
527 {int offset, bool voidContext: false, Procedure interfaceTarget}) { | 531 {int offset, bool voidContext: false, Procedure interfaceTarget}) { |
528 return internalError("Unhandled"); | 532 return deprecated_internalProblem("Unhandled"); |
529 } | 533 } |
530 | 534 |
531 Expression buildPostfixIncrement(Name binaryOperator, | 535 Expression buildPostfixIncrement(Name binaryOperator, |
532 {int offset, bool voidContext: false, Procedure interfaceTarget}) { | 536 {int offset, bool voidContext: false, Procedure interfaceTarget}) { |
533 return internalError("Unhandled"); | 537 return deprecated_internalProblem("Unhandled"); |
534 } | 538 } |
535 | 539 |
536 Expression doInvocation(int offset, Arguments arguments) { | 540 Expression doInvocation(int offset, Arguments arguments) { |
537 return internalError("Unhandled"); | 541 return deprecated_internalProblem("Unhandled"); |
538 } | 542 } |
539 | 543 |
540 toString() { | 544 toString() { |
541 int offset = offsetForToken(token); | 545 int offset = offsetForToken(token); |
542 return "SendAccessor($offset, $name, $arguments)"; | 546 return "SendAccessor($offset, $name, $arguments)"; |
543 } | 547 } |
544 } | 548 } |
545 | 549 |
546 class IncompletePropertyAccessor extends IncompleteSend { | 550 class IncompletePropertyAccessor extends IncompleteSend { |
547 IncompletePropertyAccessor(BuilderHelper helper, Token token, Name name) | 551 IncompletePropertyAccessor(BuilderHelper helper, Token token, Name name) |
548 : super(helper, token, name); | 552 : super(helper, token, name); |
549 | 553 |
550 String get plainNameForRead => name.name; | 554 String get plainNameForRead => name.name; |
551 | 555 |
552 Expression buildSimpleRead() => internalError("Unhandled"); | 556 Expression buildSimpleRead() => deprecated_internalProblem("Unhandled"); |
553 | 557 |
554 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 558 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
555 return internalError("Unhandled"); | 559 return deprecated_internalProblem("Unhandled"); |
556 } | 560 } |
557 | 561 |
558 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { | 562 withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) { |
559 if (receiver is FastaAccessor) { | 563 if (receiver is FastaAccessor) { |
560 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); | 564 return receiver.buildPropertyAccess(this, operatorOffset, isNullAware); |
561 } | 565 } |
562 if (receiver is PrefixBuilder) { | 566 if (receiver is PrefixBuilder) { |
563 PrefixBuilder prefix = receiver; | 567 PrefixBuilder prefix = receiver; |
564 if (isNullAware) { | 568 if (isNullAware) { |
565 helper.addCompileTimeError( | 569 helper.deprecated_addCompileTimeError( |
566 offsetForToken(token), | 570 offsetForToken(token), |
567 "Library prefix '${prefix.name}' can't be used with null-aware " | 571 "Library prefix '${prefix.name}' can't be used with null-aware " |
568 "operator.\nTry removing '?'."); | 572 "operator.\nTry removing '?'."); |
569 } | 573 } |
570 return helper.scopeLookup(prefix.exports, name.name, token, | 574 return helper.scopeLookup(prefix.exports, name.name, token, |
571 isQualified: true, prefix: prefix); | 575 isQualified: true, prefix: prefix); |
572 } | 576 } |
573 | 577 |
574 return PropertyAccessor.make( | 578 return PropertyAccessor.make( |
575 helper, token, helper.toValue(receiver), name, null, null, isNullAware); | 579 helper, token, helper.toValue(receiver), name, null, null, isNullAware); |
576 } | 580 } |
577 | 581 |
578 Expression buildNullAwareAssignment( | 582 Expression buildNullAwareAssignment( |
579 Expression value, DartType type, int offset, | 583 Expression value, DartType type, int offset, |
580 {bool voidContext: false}) { | 584 {bool voidContext: false}) { |
581 return internalError("Unhandled"); | 585 return deprecated_internalProblem("Unhandled"); |
582 } | 586 } |
583 | 587 |
584 Expression buildCompoundAssignment(Name binaryOperator, Expression value, | 588 Expression buildCompoundAssignment(Name binaryOperator, Expression value, |
585 {int offset, | 589 {int offset, |
586 bool voidContext: false, | 590 bool voidContext: false, |
587 Procedure interfaceTarget, | 591 Procedure interfaceTarget, |
588 bool isPreIncDec: false}) { | 592 bool isPreIncDec: false}) { |
589 return internalError("Unhandled"); | 593 return deprecated_internalProblem("Unhandled"); |
590 } | 594 } |
591 | 595 |
592 Expression buildPrefixIncrement(Name binaryOperator, | 596 Expression buildPrefixIncrement(Name binaryOperator, |
593 {int offset, bool voidContext: false, Procedure interfaceTarget}) { | 597 {int offset, bool voidContext: false, Procedure interfaceTarget}) { |
594 return internalError("Unhandled"); | 598 return deprecated_internalProblem("Unhandled"); |
595 } | 599 } |
596 | 600 |
597 Expression buildPostfixIncrement(Name binaryOperator, | 601 Expression buildPostfixIncrement(Name binaryOperator, |
598 {int offset, bool voidContext: false, Procedure interfaceTarget}) { | 602 {int offset, bool voidContext: false, Procedure interfaceTarget}) { |
599 return internalError("Unhandled"); | 603 return deprecated_internalProblem("Unhandled"); |
600 } | 604 } |
601 | 605 |
602 Expression doInvocation(int offset, Arguments arguments) { | 606 Expression doInvocation(int offset, Arguments arguments) { |
603 return internalError("Unhandled"); | 607 return deprecated_internalProblem("Unhandled"); |
604 } | 608 } |
605 | 609 |
606 toString() { | 610 toString() { |
607 int offset = offsetForToken(token); | 611 int offset = offsetForToken(token); |
608 return "IncompletePropertyAccessor($offset, $name)"; | 612 return "IncompletePropertyAccessor($offset, $name)"; |
609 } | 613 } |
610 } | 614 } |
611 | 615 |
612 class IndexAccessor extends kernel.IndexAccessor with FastaAccessor { | 616 class IndexAccessor extends kernel.IndexAccessor with FastaAccessor { |
613 final BuilderHelper helper; | 617 final BuilderHelper helper; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 695 |
692 class StaticAccessor extends kernel.StaticAccessor with FastaAccessor { | 696 class StaticAccessor extends kernel.StaticAccessor with FastaAccessor { |
693 StaticAccessor( | 697 StaticAccessor( |
694 BuilderHelper helper, Token token, Member readTarget, Member writeTarget) | 698 BuilderHelper helper, Token token, Member readTarget, Member writeTarget) |
695 : super(helper, readTarget, writeTarget, token) { | 699 : super(helper, readTarget, writeTarget, token) { |
696 assert(readTarget != null || writeTarget != null); | 700 assert(readTarget != null || writeTarget != null); |
697 } | 701 } |
698 | 702 |
699 factory StaticAccessor.fromBuilder(BuilderHelper helper, Builder builder, | 703 factory StaticAccessor.fromBuilder(BuilderHelper helper, Builder builder, |
700 Token token, Builder builderSetter) { | 704 Token token, Builder builderSetter) { |
701 if (builder is AccessErrorBuilder) { | 705 if (builder is deprecated_AccessErrorBuilder) { |
702 AccessErrorBuilder error = builder; | 706 deprecated_AccessErrorBuilder error = builder; |
703 builder = error.builder; | 707 builder = error.builder; |
704 // We should only see an access error here if we've looked up a setter | 708 // We should only see an access error here if we've looked up a setter |
705 // when not explicitly looking for a setter. | 709 // when not explicitly looking for a setter. |
706 assert(builder.isSetter); | 710 assert(builder.isSetter); |
707 } else if (builder.target == null) { | 711 } else if (builder.target == null) { |
708 return internalError("Unhandled: ${builder}"); | 712 return deprecated_internalProblem("Unhandled: ${builder}"); |
709 } | 713 } |
710 Member getter = builder.target.hasGetter ? builder.target : null; | 714 Member getter = builder.target.hasGetter ? builder.target : null; |
711 Member setter = builder.target.hasSetter ? builder.target : null; | 715 Member setter = builder.target.hasSetter ? builder.target : null; |
712 if (setter == null) { | 716 if (setter == null) { |
713 if (builderSetter?.target?.hasSetter ?? false) { | 717 if (builderSetter?.target?.hasSetter ?? false) { |
714 setter = builderSetter.target; | 718 setter = builderSetter.target; |
715 } | 719 } |
716 } | 720 } |
717 return new StaticAccessor(helper, token, getter, setter); | 721 return new StaticAccessor(helper, token, getter, setter); |
718 } | 722 } |
719 | 723 |
720 String get plainNameForRead => (readTarget ?? writeTarget).name.name; | 724 String get plainNameForRead => (readTarget ?? writeTarget).name.name; |
721 | 725 |
722 Expression doInvocation(int offset, Arguments arguments) { | 726 Expression doInvocation(int offset, Arguments arguments) { |
723 if (helper.constantExpressionRequired && !helper.isIdentical(readTarget)) { | 727 if (helper.constantExpressionRequired && !helper.isIdentical(readTarget)) { |
724 helper.addCompileTimeError(offset, "Not a constant expression."); | 728 helper.deprecated_addCompileTimeError( |
| 729 offset, "Not a constant expression."); |
725 } | 730 } |
726 if (readTarget == null || isFieldOrGetter(readTarget)) { | 731 if (readTarget == null || isFieldOrGetter(readTarget)) { |
727 return helper.buildMethodInvocation(buildSimpleRead(), callName, | 732 return helper.buildMethodInvocation(buildSimpleRead(), callName, |
728 arguments, offset + (readTarget?.name?.name?.length ?? 0), | 733 arguments, offset + (readTarget?.name?.name?.length ?? 0), |
729 // This isn't a constant expression, but we have checked if a | 734 // This isn't a constant expression, but we have checked if a |
730 // constant expression error should be emitted already. | 735 // constant expression error should be emitted already. |
731 isConstantExpression: true, | 736 isConstantExpression: true, |
732 isImplicitCall: true); | 737 isImplicitCall: true); |
733 } else { | 738 } else { |
734 return helper.buildStaticInvocation(readTarget, arguments) | 739 return helper.buildStaticInvocation(readTarget, arguments) |
(...skipping 11 matching lines...) Expand all Loading... |
746 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor | 751 class SuperPropertyAccessor extends kernel.SuperPropertyAccessor |
747 with FastaAccessor { | 752 with FastaAccessor { |
748 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, | 753 SuperPropertyAccessor(BuilderHelper helper, Token token, Name name, |
749 Member getter, Member setter) | 754 Member getter, Member setter) |
750 : super(helper, name, getter, setter, token); | 755 : super(helper, name, getter, setter, token); |
751 | 756 |
752 String get plainNameForRead => name.name; | 757 String get plainNameForRead => name.name; |
753 | 758 |
754 Expression doInvocation(int offset, Arguments arguments) { | 759 Expression doInvocation(int offset, Arguments arguments) { |
755 if (helper.constantExpressionRequired) { | 760 if (helper.constantExpressionRequired) { |
756 helper.addCompileTimeError(offset, "Not a constant expression."); | 761 helper.deprecated_addCompileTimeError( |
| 762 offset, "Not a constant expression."); |
757 } | 763 } |
758 if (getter == null || isFieldOrGetter(getter)) { | 764 if (getter == null || isFieldOrGetter(getter)) { |
759 return helper.buildMethodInvocation( | 765 return helper.buildMethodInvocation( |
760 buildSimpleRead(), callName, arguments, offset, | 766 buildSimpleRead(), callName, arguments, offset, |
761 // This isn't a constant expression, but we have checked if a | 767 // This isn't a constant expression, but we have checked if a |
762 // constant expression error should be emitted already. | 768 // constant expression error should be emitted already. |
763 isConstantExpression: true, | 769 isConstantExpression: true, |
764 isImplicitCall: true); | 770 isImplicitCall: true); |
765 } else { | 771 } else { |
766 // TODO(ahe): This could be something like "super.property(...)" where | 772 // TODO(ahe): This could be something like "super.property(...)" where |
767 // property is a setter. | 773 // property is a setter. |
768 return internalError("Unhandled invocation ${getter.runtimeType}.", | 774 return deprecated_internalProblem( |
769 helper.uri, offsetForToken(token)); | 775 "Unhandled invocation ${getter.runtimeType}.", |
| 776 helper.uri, |
| 777 offsetForToken(token)); |
770 } | 778 } |
771 } | 779 } |
772 | 780 |
773 toString() => "SuperPropertyAccessor()"; | 781 toString() => "SuperPropertyAccessor()"; |
774 | 782 |
775 @override | 783 @override |
776 KernelComplexAssignment startComplexAssignment(Expression rhs) => | 784 KernelComplexAssignment startComplexAssignment(Expression rhs) => |
777 new KernelPropertyAssign(null, rhs, isSuper: true); | 785 new KernelPropertyAssign(null, rhs, isSuper: true); |
778 } | 786 } |
779 | 787 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 with FastaAccessor { | 863 with FastaAccessor { |
856 final BuilderHelper helper; | 864 final BuilderHelper helper; |
857 | 865 |
858 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, | 866 NullAwarePropertyAccessor(this.helper, Token token, Expression receiver, |
859 Name name, Member getter, Member setter, DartType type) | 867 Name name, Member getter, Member setter, DartType type) |
860 : super(helper, receiver, name, getter, setter, type, token); | 868 : super(helper, receiver, name, getter, setter, type, token); |
861 | 869 |
862 String get plainNameForRead => name.name; | 870 String get plainNameForRead => name.name; |
863 | 871 |
864 Expression doInvocation(int offset, Arguments arguments) { | 872 Expression doInvocation(int offset, Arguments arguments) { |
865 return internalError("Not implemented yet."); | 873 return deprecated_internalProblem("Not implemented yet."); |
866 } | 874 } |
867 | 875 |
868 toString() => "NullAwarePropertyAccessor()"; | 876 toString() => "NullAwarePropertyAccessor()"; |
869 | 877 |
870 @override | 878 @override |
871 KernelComplexAssignment startComplexAssignment(Expression rhs) => | 879 KernelComplexAssignment startComplexAssignment(Expression rhs) => |
872 new KernelPropertyAssign(receiverExpression, rhs); | 880 new KernelPropertyAssign(receiverExpression, rhs); |
873 } | 881 } |
874 | 882 |
875 int adjustForImplicitCall(String name, int offset) { | 883 int adjustForImplicitCall(String name, int offset) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 isImplicitCall: true); | 920 isImplicitCall: true); |
913 } | 921 } |
914 } | 922 } |
915 | 923 |
916 class ParenthesizedExpression extends ReadOnlyAccessor { | 924 class ParenthesizedExpression extends ReadOnlyAccessor { |
917 ParenthesizedExpression( | 925 ParenthesizedExpression( |
918 BuilderHelper helper, Expression expression, Token token) | 926 BuilderHelper helper, Expression expression, Token token) |
919 : super(helper, expression, null, token); | 927 : super(helper, expression, null, token); |
920 | 928 |
921 Expression makeInvalidWrite(Expression value) { | 929 Expression makeInvalidWrite(Expression value) { |
922 return helper.buildCompileTimeError( | 930 return helper.deprecated_buildCompileTimeError( |
923 "Can't assign to a parenthesized expression.", offsetForToken(token)); | 931 "Can't assign to a parenthesized expression.", offsetForToken(token)); |
924 } | 932 } |
925 } | 933 } |
926 | 934 |
927 class TypeDeclarationAccessor extends ReadOnlyAccessor { | 935 class TypeDeclarationAccessor extends ReadOnlyAccessor { |
928 final TypeDeclarationBuilder declaration; | 936 final TypeDeclarationBuilder declaration; |
929 | 937 |
930 TypeDeclarationAccessor(BuilderHelper helper, this.declaration, | 938 TypeDeclarationAccessor(BuilderHelper helper, this.declaration, |
931 String plainNameForRead, Token token) | 939 String plainNameForRead, Token token) |
932 : super(helper, null, plainNameForRead, token); | 940 : super(helper, null, plainNameForRead, token); |
933 | 941 |
934 Expression get expression { | 942 Expression get expression { |
935 if (super.expression == null) { | 943 if (super.expression == null) { |
936 int offset = offsetForToken(token); | 944 int offset = offsetForToken(token); |
937 if (declaration is KernelInvalidTypeBuilder) { | 945 if (declaration is KernelInvalidTypeBuilder) { |
938 KernelInvalidTypeBuilder declaration = this.declaration; | 946 KernelInvalidTypeBuilder declaration = this.declaration; |
939 String message = declaration.message; | 947 String message = declaration.message; |
940 helper.library.addWarning(declaration.charOffset, message, | 948 helper.library.deprecated_addWarning(declaration.charOffset, message, |
941 fileUri: declaration.fileUri); | 949 fileUri: declaration.fileUri); |
942 helper.warning(message, offset); | 950 helper.deprecated_warning(message, offset); |
943 super.expression = new Throw( | 951 super.expression = new Throw( |
944 new StringLiteral(message)..fileOffset = offsetForToken(token)) | 952 new StringLiteral(message)..fileOffset = offsetForToken(token)) |
945 ..fileOffset = offset; | 953 ..fileOffset = offset; |
946 } else { | 954 } else { |
947 super.expression = new KernelTypeLiteral( | 955 super.expression = new KernelTypeLiteral( |
948 buildType(null, nonInstanceAccessIsError: true)) | 956 buildType(null, nonInstanceAccessIsError: true)) |
949 ..fileOffset = offsetForToken(token); | 957 ..fileOffset = offsetForToken(token); |
950 } | 958 } |
951 } | 959 } |
952 return super.expression; | 960 return super.expression; |
(...skipping 16 matching lines...) Expand all Loading... |
969 Name name = send.name; | 977 Name name = send.name; |
970 Arguments arguments = send.arguments; | 978 Arguments arguments = send.arguments; |
971 | 979 |
972 if (declaration is KernelClassBuilder) { | 980 if (declaration is KernelClassBuilder) { |
973 KernelClassBuilder declaration = this.declaration; | 981 KernelClassBuilder declaration = this.declaration; |
974 Builder builder = declaration.findStaticBuilder( | 982 Builder builder = declaration.findStaticBuilder( |
975 name.name, offsetForToken(token), uri, helper.library); | 983 name.name, offsetForToken(token), uri, helper.library); |
976 | 984 |
977 FastaAccessor accessor; | 985 FastaAccessor accessor; |
978 if (builder == null) { | 986 if (builder == null) { |
979 // If we find a setter, [builder] is an [AccessErrorBuilder], not null. | 987 // If we find a setter, [builder] is an |
| 988 // [deprecated_AccessErrorBuilder], not null. |
980 accessor = new UnresolvedAccessor(helper, name, token); | 989 accessor = new UnresolvedAccessor(helper, name, token); |
981 } else { | 990 } else { |
982 Builder setter; | 991 Builder setter; |
983 if (builder.isSetter) { | 992 if (builder.isSetter) { |
984 setter = builder; | 993 setter = builder; |
985 } else if (builder.isGetter) { | 994 } else if (builder.isGetter) { |
986 setter = declaration.findStaticBuilder( | 995 setter = declaration.findStaticBuilder( |
987 name.name, offsetForToken(token), uri, helper.library, | 996 name.name, offsetForToken(token), uri, helper.library, |
988 isSetter: true); | 997 isSetter: true); |
989 } else if (builder.isField && !builder.isFinal) { | 998 } else if (builder.isField && !builder.isFinal) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 offset ??= offsetForToken(this.token); | 1044 offset ??= offsetForToken(this.token); |
1036 return helper.throwNoSuchMethodError(new NullLiteral()..fileOffset = offset, | 1045 return helper.throwNoSuchMethodError(new NullLiteral()..fileOffset = offset, |
1037 plainNameForRead, arguments, offset, | 1046 plainNameForRead, arguments, offset, |
1038 isGetter: isGetter, isSetter: isSetter); | 1047 isGetter: isGetter, isSetter: isSetter); |
1039 } | 1048 } |
1040 } | 1049 } |
1041 | 1050 |
1042 bool isFieldOrGetter(Member member) { | 1051 bool isFieldOrGetter(Member member) { |
1043 return member is Field || (member is Procedure && member.isGetter); | 1052 return member is Field || (member is Procedure && member.isGetter); |
1044 } | 1053 } |
OLD | NEW |