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

Side by Side Diff: pkg/kernel/lib/text/ast_to_text.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/kernel.dart ('k') | pkg/kernel/lib/transformations/async.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 library kernel.ast_to_text; 4 library kernel.ast_to_text;
5 5
6 import '../ast.dart'; 6 import '../ast.dart';
7 import '../import_table.dart'; 7 import '../import_table.dart';
8 import '../type_propagation/type_propagation.dart'; 8 import '../type_propagation/type_propagation.dart';
9 9
10 class Namer<T> { 10 class Namer<T> {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 /// A quick and dirty ambiguous text printer. 175 /// A quick and dirty ambiguous text printer.
176 class Printer extends Visitor<Null> { 176 class Printer extends Visitor<Null> {
177 final NameSystem syntheticNames; 177 final NameSystem syntheticNames;
178 final StringSink sink; 178 final StringSink sink;
179 final Annotator annotator; 179 final Annotator annotator;
180 ImportTable importTable; 180 ImportTable importTable;
181 int indentation = 0; 181 int indentation = 0;
182 int column = 0; 182 int column = 0;
183 bool showExternal; 183 bool showExternal;
184 bool showOffsets;
185 184
186 static int SPACE = 0; 185 static int SPACE = 0;
187 static int WORD = 1; 186 static int WORD = 1;
188 static int SYMBOL = 2; 187 static int SYMBOL = 2;
189 int state = SPACE; 188 int state = SPACE;
190 189
191 Printer(this.sink, 190 Printer(this.sink,
192 {NameSystem syntheticNames, 191 {NameSystem syntheticNames,
193 this.showExternal, 192 this.showExternal,
194 this.showOffsets,
195 this.importTable, 193 this.importTable,
196 this.annotator: const InferredValueAnnotator()}) 194 this.annotator: const InferredValueAnnotator()})
197 : this.syntheticNames = syntheticNames ?? new NameSystem(); 195 : this.syntheticNames = syntheticNames ?? new NameSystem();
198 196
199 Printer._inner(Printer parent, this.importTable) 197 Printer._inner(Printer parent, this.importTable)
200 : sink = parent.sink, 198 : sink = parent.sink,
201 syntheticNames = parent.syntheticNames, 199 syntheticNames = parent.syntheticNames,
202 annotator = parent.annotator, 200 annotator = parent.annotator,
203 showExternal = parent.showExternal, 201 showExternal = parent.showExternal;
204 showOffsets = parent.showOffsets;
205 202
206 String getLibraryName(Library node) { 203 String getLibraryName(Library node) {
207 return node.name ?? syntheticNames.nameLibrary(node); 204 return node.name ?? syntheticNames.nameLibrary(node);
208 } 205 }
209 206
210 String getLibraryReference(Library node) { 207 String getLibraryReference(Library node) {
211 if (node == null) return '<No Library>'; 208 if (node == null) return '<No Library>';
212 if (importTable != null && importTable.getImportIndex(node) != -1) { 209 if (importTable != null && importTable.getImportIndex(node) != -1) {
213 return syntheticNames.nameLibraryPrefix(node); 210 return syntheticNames.nameLibraryPrefix(node);
214 } 211 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (state == WORD) { 386 if (state == WORD) {
390 writeSpace(); 387 writeSpace();
391 } 388 }
392 } 389 }
393 390
394 void writeIndentation() { 391 void writeIndentation() {
395 writeSpace(' ' * indentation); 392 writeSpace(' ' * indentation);
396 } 393 }
397 394
398 void writeNode(Node node) { 395 void writeNode(Node node) {
399 if (showOffsets && node is TreeNode) {
400 writeWord("[${node.fileOffset}]");
401 }
402 node.accept(this); 396 node.accept(this);
403 } 397 }
404 398
405 void writeOptionalNode(Node node) { 399 void writeOptionalNode(Node node) {
406 if (node != null) { 400 if (node != null) {
407 node.accept(this); 401 node.accept(this);
408 } 402 }
409 } 403 }
410 404
411 void writeAnnotatedType(DartType type, String annotation) { 405 void writeAnnotatedType(DartType type, String annotation) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 endLine(); 479 endLine();
486 ++indentation; 480 ++indentation;
487 writeIndentation(); 481 writeIndentation();
488 writeComma(':'); 482 writeComma(':');
489 writeList(initializers, writeNode); 483 writeList(initializers, writeNode);
490 --indentation; 484 --indentation;
491 } 485 }
492 if (function.asyncMarker != AsyncMarker.Sync) { 486 if (function.asyncMarker != AsyncMarker.Sync) {
493 writeSpaced(getAsyncMarkerKeyword(function.asyncMarker)); 487 writeSpaced(getAsyncMarkerKeyword(function.asyncMarker));
494 } 488 }
495 if (!function.debuggable) writeSpaced("/* not debuggable */");
496 if (function.body != null) { 489 if (function.body != null) {
497 writeFunctionBody(function.body, terminateLine: terminateLine); 490 writeFunctionBody(function.body, terminateLine: terminateLine);
498 } else if (terminateLine) { 491 } else if (terminateLine) {
499 endLine(';'); 492 endLine(';');
500 } 493 }
501 } 494 }
502 495
503 String getAsyncMarkerKeyword(AsyncMarker marker) { 496 String getAsyncMarkerKeyword(AsyncMarker marker) {
504 switch (marker) { 497 switch (marker) {
505 case AsyncMarker.Sync: 498 case AsyncMarker.Sync:
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 619
627 void writeVariableReference(VariableDeclaration variable) { 620 void writeVariableReference(VariableDeclaration variable) {
628 writeWord(getVariableReference(variable)); 621 writeWord(getVariableReference(variable));
629 } 622 }
630 623
631 void writeTypeParameterReference(TypeParameter node) { 624 void writeTypeParameterReference(TypeParameter node) {
632 writeWord(getTypeParameterReference(node)); 625 writeWord(getTypeParameterReference(node));
633 } 626 }
634 627
635 void writeExpression(Expression node, [int minimumPrecedence]) { 628 void writeExpression(Expression node, [int minimumPrecedence]) {
636 if (showOffsets) writeWord("[${node.fileOffset}]");
637 bool needsParenteses = false; 629 bool needsParenteses = false;
638 if (minimumPrecedence != null && getPrecedence(node) < minimumPrecedence) { 630 if (minimumPrecedence != null && getPrecedence(node) < minimumPrecedence) {
639 needsParenteses = true; 631 needsParenteses = true;
640 writeSymbol('('); 632 writeSymbol('(');
641 } 633 }
642 writeNode(node); 634 writeNode(node);
643 if (needsParenteses) { 635 if (needsParenteses) {
644 writeSymbol(')'); 636 writeSymbol(')');
645 } 637 }
646 } 638 }
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 } 1280 }
1289 1281
1290 visitFunctionDeclaration(FunctionDeclaration node) { 1282 visitFunctionDeclaration(FunctionDeclaration node) {
1291 writeIndentation(); 1283 writeIndentation();
1292 writeWord('function'); 1284 writeWord('function');
1293 writeFunction(node.function, name: getVariableName(node.variable)); 1285 writeFunction(node.function, name: getVariableName(node.variable));
1294 } 1286 }
1295 1287
1296 void writeVariableDeclaration(VariableDeclaration node, 1288 void writeVariableDeclaration(VariableDeclaration node,
1297 {bool useVarKeyword: false}) { 1289 {bool useVarKeyword: false}) {
1298 if (showOffsets) writeWord("[${node.fileOffset}]");
1299 writeModifier(node.isFinal, 'final'); 1290 writeModifier(node.isFinal, 'final');
1300 writeModifier(node.isConst, 'const'); 1291 writeModifier(node.isConst, 'const');
1301 if (node.type != null) { 1292 if (node.type != null) {
1302 writeAnnotatedType(node.type, annotator?.annotateVariable(this, node)); 1293 writeAnnotatedType(node.type, annotator?.annotateVariable(this, node));
1303 } 1294 }
1304 if (useVarKeyword && !node.isFinal && !node.isConst && node.type == null) { 1295 if (useVarKeyword && !node.isFinal && !node.isConst && node.type == null) {
1305 writeWord('var'); 1296 writeWord('var');
1306 } 1297 }
1307 writeWord(getVariableName(node)); 1298 writeWord(getVariableName(node));
1308 if (node.initializer != null) { 1299 if (node.initializer != null) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 } 1535 }
1545 throw 'illegal ProcedureKind: $kind'; 1536 throw 'illegal ProcedureKind: $kind';
1546 } 1537 }
1547 1538
1548 class ExpressionPrinter { 1539 class ExpressionPrinter {
1549 final Printer writeer; 1540 final Printer writeer;
1550 final int minimumPrecedence; 1541 final int minimumPrecedence;
1551 1542
1552 ExpressionPrinter(this.writeer, this.minimumPrecedence); 1543 ExpressionPrinter(this.writeer, this.minimumPrecedence);
1553 } 1544 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/kernel.dart ('k') | pkg/kernel/lib/transformations/async.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698