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

Side by Side Diff: pkg/compiler/lib/src/js/js.dart

Issue 1100723002: Add SourceInformationFactory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 js; 5 library js;
6 6
7 import 'package:js_ast/js_ast.dart'; 7 import 'package:js_ast/js_ast.dart';
8 export 'package:js_ast/js_ast.dart'; 8 export 'package:js_ast/js_ast.dart';
9 9
10 import '../helpers/helpers.dart';
10 import '../io/code_output.dart' show CodeBuffer; 11 import '../io/code_output.dart' show CodeBuffer;
11 import '../io/source_information.dart' show SourceInformation; 12 import '../io/source_information.dart' show SourceInformation;
12 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; 13 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER;
13 import '../dart2jslib.dart' as leg; 14 import '../dart2jslib.dart' as leg;
14 import '../util/util.dart' show NO_LOCATION_SPANNABLE; 15 import '../util/util.dart' show NO_LOCATION_SPANNABLE;
15 import '../dump_info.dart' show DumpInfoTask; 16 import '../dump_info.dart' show DumpInfoTask;
16 17
17 18
18 CodeBuffer prettyPrint(Node node, leg.Compiler compiler, 19 CodeBuffer prettyPrint(Node node, leg.Compiler compiler,
19 {DumpInfoTask monitor, 20 {DumpInfoTask monitor,
(...skipping 11 matching lines...) Expand all
31 32
32 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext { 33 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext {
33 final leg.Compiler compiler; 34 final leg.Compiler compiler;
34 final DumpInfoTask monitor; 35 final DumpInfoTask monitor;
35 final CodeBuffer outBuffer = new CodeBuffer(); 36 final CodeBuffer outBuffer = new CodeBuffer();
36 Node rootNode; 37 Node rootNode;
37 38
38 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler, 39 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler,
39 DumpInfoTask this.monitor); 40 DumpInfoTask this.monitor);
40 41
42 @override
41 void error(String message) { 43 void error(String message) {
42 compiler.internalError(NO_LOCATION_SPANNABLE, message); 44 compiler.internalError(NO_LOCATION_SPANNABLE, message);
43 } 45 }
44 46
47 @override
45 void emit(String string) { 48 void emit(String string) {
46 outBuffer.add(string); 49 outBuffer.add(string);
47 } 50 }
48 51
52 @override
49 void enterNode(Node node, int startPosition) { 53 void enterNode(Node node, int startPosition) {
50 SourceInformation sourceInformation = node.sourceInformation; 54 SourceInformation sourceInformation = node.sourceInformation;
51 if (sourceInformation != null) { 55 if (sourceInformation != null) {
52 if (rootNode == null) { 56 if (rootNode == null) {
53 rootNode = node; 57 rootNode = node;
54 } 58 }
55 if (sourceInformation.startPosition != null) { 59 if (sourceInformation.startPosition != null) {
56 outBuffer.addSourceLocation( 60 outBuffer.addSourceLocation(
57 startPosition, sourceInformation.startPosition); 61 startPosition, sourceInformation.startPosition);
58 } 62 }
59 } 63 }
60 } 64 }
61 65
62 void exitNode(Node node, 66 void exitNode(Node node,
63 int startPosition, 67 int startPosition,
64 int endPosition, 68 int endPosition,
65 int closingPosition) { 69 int closingPosition) {
66 SourceInformation sourceInformation = node.sourceInformation; 70 SourceInformation sourceInformation = node.sourceInformation;
67 if (sourceInformation != null) { 71 if (sourceInformation != null) {
72 if (closingPosition != null &&
73 sourceInformation.closingPosition != null) {
74 outBuffer.addSourceLocation(
75 closingPosition, sourceInformation.closingPosition);
76 }
68 if (sourceInformation.endPosition != null) { 77 if (sourceInformation.endPosition != null) {
69 outBuffer.addSourceLocation(endPosition, sourceInformation.endPosition); 78 outBuffer.addSourceLocation(endPosition, sourceInformation.endPosition);
70 } 79 }
71 if (rootNode == node) { 80 if (rootNode == node) {
72 outBuffer.addSourceLocation(endPosition, null); 81 outBuffer.addSourceLocation(endPosition, null);
73 rootNode = null; 82 rootNode = null;
74 } 83 }
75 } 84 }
76 if (monitor != null) { 85 if (monitor != null) {
77 monitor.recordAstSize(node, endPosition - startPosition); 86 monitor.recordAstSize(node, endPosition - startPosition);
78 } 87 }
79 } 88 }
80 } 89 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/io/source_information.dart ('k') | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698