| 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 /// A library to help transform compounds and null-aware accessors into | 5 /// A library to help transform compounds and null-aware accessors into |
| 6 /// let expressions. | 6 /// let expressions. |
| 7 library kernel.frontend.accessors; | 7 library kernel.frontend.accessors; |
| 8 | 8 |
| 9 import '../ast.dart'; | 9 import '../ast.dart'; |
| 10 | 10 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 new ConditionalExpression( | 178 new ConditionalExpression( |
| 179 buildIsNull(receiverAccess()), new NullLiteral(), body, type)); | 179 buildIsNull(receiverAccess()), new NullLiteral(), body, type)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 class SuperPropertyAccessor extends Accessor { | 182 class SuperPropertyAccessor extends Accessor { |
| 183 Name name; | 183 Name name; |
| 184 Member getter, setter; | 184 Member getter, setter; |
| 185 | 185 |
| 186 SuperPropertyAccessor(this.name, this.getter, this.setter); | 186 SuperPropertyAccessor(this.name, this.getter, this.setter); |
| 187 | 187 |
| 188 _makeRead() => new SuperPropertyGet(name, getter); | 188 _makeRead() => builtGetter = new SuperPropertyGet(name, getter); |
| 189 | 189 |
| 190 _makeWrite(Expression value, bool voidContext) { | 190 _makeWrite(Expression value, bool voidContext) { |
| 191 return new SuperPropertySet(name, value, setter); | 191 return new SuperPropertySet(name, value, setter); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 final Name _indexGet = new Name('[]'); | 195 final Name _indexGet = new Name('[]'); |
| 196 final Name _indexSet = new Name('[]='); | 196 final Name _indexSet = new Name('[]='); |
| 197 | 197 |
| 198 class IndexAccessor extends Accessor { | 198 class IndexAccessor extends Accessor { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 228 receiverVariable ??= new VariableDeclaration.forValue(receiver); | 228 receiverVariable ??= new VariableDeclaration.forValue(receiver); |
| 229 return new VariableGet(receiverVariable); | 229 return new VariableGet(receiverVariable); |
| 230 } | 230 } |
| 231 | 231 |
| 232 indexAccess() { | 232 indexAccess() { |
| 233 indexVariable ??= new VariableDeclaration.forValue(index); | 233 indexVariable ??= new VariableDeclaration.forValue(index); |
| 234 return new VariableGet(indexVariable); | 234 return new VariableGet(indexVariable); |
| 235 } | 235 } |
| 236 | 236 |
| 237 _makeRead() { | 237 _makeRead() { |
| 238 return new MethodInvocation(receiverAccess(), _indexGet, | 238 return builtGetter = new MethodInvocation(receiverAccess(), _indexGet, |
| 239 new Arguments(<Expression>[indexAccess()]), getter); | 239 new Arguments(<Expression>[indexAccess()]), getter); |
| 240 } | 240 } |
| 241 | 241 |
| 242 _makeWrite(Expression value, bool voidContext) { | 242 _makeWrite(Expression value, bool voidContext) { |
| 243 if (!voidContext) return _makeWriteAndReturn(value); | 243 if (!voidContext) return _makeWriteAndReturn(value); |
| 244 return new MethodInvocation(receiverAccess(), _indexSet, | 244 return new MethodInvocation(receiverAccess(), _indexSet, |
| 245 new Arguments(<Expression>[indexAccess(), value]), setter); | 245 new Arguments(<Expression>[indexAccess(), value]), setter); |
| 246 } | 246 } |
| 247 | 247 |
| 248 _makeWriteAndReturn(Expression value) { | 248 _makeWriteAndReturn(Expression value) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (!voidContext) return _makeWriteAndReturn(value); | 282 if (!voidContext) return _makeWriteAndReturn(value); |
| 283 return new MethodInvocation(new ThisExpression(), _indexSet, | 283 return new MethodInvocation(new ThisExpression(), _indexSet, |
| 284 new Arguments(<Expression>[index, value]), setter); | 284 new Arguments(<Expression>[index, value]), setter); |
| 285 } | 285 } |
| 286 | 286 |
| 287 indexAccess() { | 287 indexAccess() { |
| 288 indexVariable ??= new VariableDeclaration.forValue(index); | 288 indexVariable ??= new VariableDeclaration.forValue(index); |
| 289 return new VariableGet(indexVariable); | 289 return new VariableGet(indexVariable); |
| 290 } | 290 } |
| 291 | 291 |
| 292 _makeRead() => new MethodInvocation(new ThisExpression(), _indexGet, | 292 _makeRead() => builtGetter = new MethodInvocation(new ThisExpression(), |
| 293 new Arguments(<Expression>[indexAccess()]), getter); | 293 _indexGet, new Arguments(<Expression>[indexAccess()]), getter); |
| 294 | 294 |
| 295 _makeWrite(Expression value, bool voidContext) { | 295 _makeWrite(Expression value, bool voidContext) { |
| 296 if (!voidContext) return _makeWriteAndReturn(value); | 296 if (!voidContext) return _makeWriteAndReturn(value); |
| 297 return new MethodInvocation(new ThisExpression(), _indexSet, | 297 return new MethodInvocation(new ThisExpression(), _indexSet, |
| 298 new Arguments(<Expression>[indexAccess(), value]), setter); | 298 new Arguments(<Expression>[indexAccess(), value]), setter); |
| 299 } | 299 } |
| 300 | 300 |
| 301 _makeWriteAndReturn(Expression value) { | 301 _makeWriteAndReturn(Expression value) { |
| 302 var valueVariable = new VariableDeclaration.forValue(value); | 302 var valueVariable = new VariableDeclaration.forValue(value); |
| 303 var dummy = new VariableDeclaration.forValue(new MethodInvocation( | 303 var dummy = new VariableDeclaration.forValue(new MethodInvocation( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 328 _makeSimpleRead() => new SuperMethodInvocation( | 328 _makeSimpleRead() => new SuperMethodInvocation( |
| 329 _indexGet, new Arguments(<Expression>[index]), getter); | 329 _indexGet, new Arguments(<Expression>[index]), getter); |
| 330 | 330 |
| 331 _makeSimpleWrite(Expression value, bool voidContext) { | 331 _makeSimpleWrite(Expression value, bool voidContext) { |
| 332 if (!voidContext) return _makeWriteAndReturn(value); | 332 if (!voidContext) return _makeWriteAndReturn(value); |
| 333 return new SuperMethodInvocation( | 333 return new SuperMethodInvocation( |
| 334 _indexSet, new Arguments(<Expression>[index, value]), setter); | 334 _indexSet, new Arguments(<Expression>[index, value]), setter); |
| 335 } | 335 } |
| 336 | 336 |
| 337 _makeRead() { | 337 _makeRead() { |
| 338 return new SuperMethodInvocation( | 338 return builtGetter = new SuperMethodInvocation( |
| 339 _indexGet, new Arguments(<Expression>[indexAccess()]), getter); | 339 _indexGet, new Arguments(<Expression>[indexAccess()]), getter); |
| 340 } | 340 } |
| 341 | 341 |
| 342 _makeWrite(Expression value, bool voidContext) { | 342 _makeWrite(Expression value, bool voidContext) { |
| 343 if (!voidContext) return _makeWriteAndReturn(value); | 343 if (!voidContext) return _makeWriteAndReturn(value); |
| 344 return new SuperMethodInvocation( | 344 return new SuperMethodInvocation( |
| 345 _indexSet, new Arguments(<Expression>[indexAccess(), value]), setter); | 345 _indexSet, new Arguments(<Expression>[indexAccess(), value]), setter); |
| 346 } | 346 } |
| 347 | 347 |
| 348 _makeWriteAndReturn(Expression value) { | 348 _makeWriteAndReturn(Expression value) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 360 return makeLet(indexVariable, body); | 360 return makeLet(indexVariable, body); |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 class StaticAccessor extends Accessor { | 364 class StaticAccessor extends Accessor { |
| 365 Member readTarget; | 365 Member readTarget; |
| 366 Member writeTarget; | 366 Member writeTarget; |
| 367 | 367 |
| 368 StaticAccessor(this.readTarget, this.writeTarget); | 368 StaticAccessor(this.readTarget, this.writeTarget); |
| 369 | 369 |
| 370 _makeRead() => | 370 _makeRead() => builtGetter = |
| 371 readTarget == null ? makeInvalidRead() : new StaticGet(readTarget); | 371 readTarget == null ? makeInvalidRead() : new StaticGet(readTarget); |
| 372 | 372 |
| 373 _makeWrite(Expression value, bool voidContext) { | 373 _makeWrite(Expression value, bool voidContext) { |
| 374 return writeTarget == null | 374 return writeTarget == null |
| 375 ? makeInvalidWrite(value) | 375 ? makeInvalidWrite(value) |
| 376 : new StaticSet(writeTarget, value); | 376 : new StaticSet(writeTarget, value); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 class ReadOnlyAccessor extends Accessor { | 380 class ReadOnlyAccessor extends Accessor { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 414 |
| 415 VariableDeclaration makeOrReuseVariable(Expression value) { | 415 VariableDeclaration makeOrReuseVariable(Expression value) { |
| 416 // TODO: Devise a way to remember if a variable declaration was reused | 416 // TODO: Devise a way to remember if a variable declaration was reused |
| 417 // or is fresh (hence needs a let binding). | 417 // or is fresh (hence needs a let binding). |
| 418 return new VariableDeclaration.forValue(value); | 418 return new VariableDeclaration.forValue(value); |
| 419 } | 419 } |
| 420 | 420 |
| 421 Expression wrapInvalid(Expression e) { | 421 Expression wrapInvalid(Expression e) { |
| 422 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); | 422 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); |
| 423 } | 423 } |
| OLD | NEW |