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

Side by Side Diff: pkg/kernel/lib/frontend/accessors.dart

Issue 2614663007: Revert "Non-format-changing kernel offset changes" (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « pkg/kernel/lib/clone.dart ('k') | pkg/kernel/lib/kernel.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 return _finish(new ConditionalExpression(buildIsNull(_makeRead()), 34 return _finish(new ConditionalExpression(buildIsNull(_makeRead()),
35 _makeWrite(value, voidContext), new NullLiteral(), type)); 35 _makeWrite(value, voidContext), new NullLiteral(), type));
36 } 36 }
37 var tmp = new VariableDeclaration.forValue(_makeRead()); 37 var tmp = new VariableDeclaration.forValue(_makeRead());
38 return _finish(makeLet( 38 return _finish(makeLet(
39 tmp, 39 tmp,
40 new ConditionalExpression(buildIsNull(new VariableGet(tmp)), 40 new ConditionalExpression(buildIsNull(new VariableGet(tmp)),
41 _makeWrite(value, voidContext), new VariableGet(tmp), type))); 41 _makeWrite(value, voidContext), new VariableGet(tmp), type)));
42 } 42 }
43 43
44 Expression buildCompoundAssignment( 44 Expression buildCompoundAssignment(Name binaryOperator, Expression value,
45 Name binaryOperator, Expression value, int offset,
46 {bool voidContext: false, Procedure interfaceTarget}) { 45 {bool voidContext: false, Procedure interfaceTarget}) {
47 return _finish(_makeWrite( 46 return _finish(_makeWrite(
48 builtBinary = makeBinary( 47 builtBinary =
49 _makeRead(), binaryOperator, interfaceTarget, value, offset), 48 makeBinary(_makeRead(), binaryOperator, interfaceTarget, value),
50 voidContext)); 49 voidContext));
51 } 50 }
52 51
53 Expression buildPrefixIncrement(Name binaryOperator, int offset, 52 Expression buildPrefixIncrement(Name binaryOperator,
54 {bool voidContext: false, Procedure interfaceTarget}) { 53 {bool voidContext: false, Procedure interfaceTarget}) {
55 return buildCompoundAssignment(binaryOperator, new IntLiteral(1), offset, 54 return buildCompoundAssignment(binaryOperator, new IntLiteral(1),
56 voidContext: voidContext, interfaceTarget: interfaceTarget); 55 voidContext: voidContext, interfaceTarget: interfaceTarget);
57 } 56 }
58 57
59 Expression buildPostfixIncrement(Name binaryOperator, int offset, 58 Expression buildPostfixIncrement(Name binaryOperator,
60 {bool voidContext: false, Procedure interfaceTarget}) { 59 {bool voidContext: false, Procedure interfaceTarget}) {
61 if (voidContext) { 60 if (voidContext) {
62 return buildPrefixIncrement(binaryOperator, offset, 61 return buildPrefixIncrement(binaryOperator,
63 voidContext: true, interfaceTarget: interfaceTarget); 62 voidContext: true, interfaceTarget: interfaceTarget);
64 } 63 }
65 var value = new VariableDeclaration.forValue(_makeRead()); 64 var value = new VariableDeclaration.forValue(_makeRead());
66 valueAccess() => new VariableGet(value); 65 valueAccess() => new VariableGet(value);
67 var dummy = new VariableDeclaration.forValue(_makeWrite( 66 var dummy = new VariableDeclaration.forValue(_makeWrite(
68 builtBinary = makeBinary(valueAccess(), binaryOperator, interfaceTarget, 67 builtBinary = makeBinary(
69 new IntLiteral(1), offset), 68 valueAccess(), binaryOperator, interfaceTarget, new IntLiteral(1)),
70 true)); 69 true));
71 return _finish(makeLet(value, makeLet(dummy, valueAccess()))); 70 return _finish(makeLet(value, makeLet(dummy, valueAccess())));
72 } 71 }
73 72
74 Expression _makeSimpleRead() => _makeRead(); 73 Expression _makeSimpleRead() => _makeRead();
75 74
76 Expression _makeSimpleWrite(Expression value, bool voidContext) { 75 Expression _makeSimpleWrite(Expression value, bool voidContext) {
77 return _makeWrite(value, voidContext); 76 return _makeWrite(value, voidContext);
78 } 77 }
79 78
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 394
396 Expression _finish(Expression body) => makeLet(value, body); 395 Expression _finish(Expression body) => makeLet(value, body);
397 } 396 }
398 397
399 Expression makeLet(VariableDeclaration variable, Expression body) { 398 Expression makeLet(VariableDeclaration variable, Expression body) {
400 if (variable == null) return body; 399 if (variable == null) return body;
401 return new Let(variable, body); 400 return new Let(variable, body);
402 } 401 }
403 402
404 Expression makeBinary(Expression left, Name operator, Procedure interfaceTarget, 403 Expression makeBinary(Expression left, Name operator, Procedure interfaceTarget,
405 Expression right, int offset) { 404 Expression right) {
406 return new MethodInvocation( 405 return new MethodInvocation(
407 left, operator, new Arguments(<Expression>[right]), interfaceTarget) 406 left, operator, new Arguments(<Expression>[right]), interfaceTarget);
408 ..fileOffset = offset;
409 } 407 }
410 408
411 final Name _equalOperator = new Name('=='); 409 final Name _equalOperator = new Name('==');
412 410
413 Expression buildIsNull(Expression value, {int offset: TreeNode.noOffset}) { 411 Expression buildIsNull(Expression value) {
414 return makeBinary(value, _equalOperator, null, new NullLiteral(), offset); 412 return makeBinary(value, _equalOperator, null, new NullLiteral());
415 } 413 }
416 414
417 VariableDeclaration makeOrReuseVariable(Expression value) { 415 VariableDeclaration makeOrReuseVariable(Expression value) {
418 // 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
419 // or is fresh (hence needs a let binding). 417 // or is fresh (hence needs a let binding).
420 return new VariableDeclaration.forValue(value); 418 return new VariableDeclaration.forValue(value);
421 } 419 }
422 420
423 Expression wrapInvalid(Expression e) { 421 Expression wrapInvalid(Expression e) {
424 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression()); 422 return new Let(new VariableDeclaration.forValue(e), new InvalidExpression());
425 } 423 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/clone.dart ('k') | pkg/kernel/lib/kernel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698