OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 class Interceptors { | 5 class Interceptors { |
6 Compiler compiler; | 6 Compiler compiler; |
7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
8 | 8 |
9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 */ | 383 */ |
384 HInstruction readLocal(Element element) { | 384 HInstruction readLocal(Element element) { |
385 if (isAccessedDirectly(element)) { | 385 if (isAccessedDirectly(element)) { |
386 if (directLocals[element] == null) { | 386 if (directLocals[element] == null) { |
387 builder.compiler.internalError("Cannot find value $element", | 387 builder.compiler.internalError("Cannot find value $element", |
388 element: element); | 388 element: element); |
389 } | 389 } |
390 return directLocals[element]; | 390 return directLocals[element]; |
391 } else if (isStoredInClosureField(element)) { | 391 } else if (isStoredInClosureField(element)) { |
392 Element redirect = redirectionMapping[element]; | 392 Element redirect = redirectionMapping[element]; |
393 // We must not use the [LocalsHandler.readThis()] since that could | 393 HInstruction receiver = readLocal(closureData.closureElement); |
394 // point to a captured this which would be stored in a closure-field | |
395 // itself. | |
396 HInstruction receiver = new HThis(); | |
397 builder.add(receiver); | |
398 HInstruction fieldGet = new HFieldGet(redirect, receiver); | 394 HInstruction fieldGet = new HFieldGet(redirect, receiver); |
399 builder.add(fieldGet); | 395 builder.add(fieldGet); |
400 return fieldGet; | 396 return fieldGet; |
401 } else if (isBoxed(element)) { | 397 } else if (isBoxed(element)) { |
402 Element redirect = redirectionMapping[element]; | 398 Element redirect = redirectionMapping[element]; |
403 // In the function that declares the captured variable the box is | 399 // In the function that declares the captured variable the box is |
404 // accessed as direct local. Inside the nested closure the box is | 400 // accessed as direct local. Inside the nested closure the box is |
405 // accessed through a closure-field. | 401 // accessed through a closure-field. |
406 // Calling [readLocal] makes sure we generate the correct code to get | 402 // Calling [readLocal] makes sure we generate the correct code to get |
407 // the box. | 403 // the box. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 449 |
454 /** | 450 /** |
455 * Sets the [element] to [value]. If the element is boxed or stored in a | 451 * Sets the [element] to [value]. If the element is boxed or stored in a |
456 * closure then the method generates code to set the value. | 452 * closure then the method generates code to set the value. |
457 */ | 453 */ |
458 void updateLocal(Element element, HInstruction value) { | 454 void updateLocal(Element element, HInstruction value) { |
459 if (isAccessedDirectly(element)) { | 455 if (isAccessedDirectly(element)) { |
460 directLocals[element] = value; | 456 directLocals[element] = value; |
461 } else if (isStoredInClosureField(element)) { | 457 } else if (isStoredInClosureField(element)) { |
462 Element redirect = redirectionMapping[element]; | 458 Element redirect = redirectionMapping[element]; |
463 // We must not use the [LocalsHandler.readThis()] since that could | 459 HInstruction receiver = readLocal(closureData.closureElement); |
464 // point to a captured this which would be stored in a closure-field | |
465 // itself. | |
466 HInstruction receiver = new HThis(); | |
467 builder.add(receiver); | |
468 builder.add(new HFieldSet(redirect.name, receiver, value)); | 460 builder.add(new HFieldSet(redirect.name, receiver, value)); |
469 } else if (isBoxed(element)) { | 461 } else if (isBoxed(element)) { |
470 Element redirect = redirectionMapping[element]; | 462 Element redirect = redirectionMapping[element]; |
471 // The box itself could be captured, or be local. A local variable that | 463 // The box itself could be captured, or be local. A local variable that |
472 // is captured will be boxed, but the box itself will be a local. | 464 // is captured will be boxed, but the box itself will be a local. |
473 // Inside the closure the box is stored in a closure-field and cannot | 465 // Inside the closure the box is stored in a closure-field and cannot |
474 // be accessed directly. | 466 // be accessed directly. |
475 assert(redirect.enclosingElement.kind == ElementKind.VARIABLE); | 467 assert(redirect.enclosingElement.kind == ElementKind.VARIABLE); |
476 HInstruction box = readLocal(redirect.enclosingElement); | 468 HInstruction box = readLocal(redirect.enclosingElement); |
477 builder.add(new HFieldSet(redirect, box, value)); | 469 builder.add(new HFieldSet(redirect, box, value)); |
(...skipping 2915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3393 <HInstruction>[target, input], | 3385 <HInstruction>[target, input], |
3394 HType.STRING)); | 3386 HType.STRING)); |
3395 return builder.pop(); | 3387 return builder.pop(); |
3396 } | 3388 } |
3397 | 3389 |
3398 HInstruction result(Node node) { | 3390 HInstruction result(Node node) { |
3399 flushLiterals(node); | 3391 flushLiterals(node); |
3400 return prefix; | 3392 return prefix; |
3401 } | 3393 } |
3402 } | 3394 } |
OLD | NEW |