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

Side by Side Diff: tests/compiler/dart2js/memory_compiler.dart

Issue 189563004: Use '--source-map' and '--out' options to support source maps from non-commandline. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.test.memory_compiler; 5 library dart2js.test.memory_compiler;
6 6
7 import 'memory_source_file_helper.dart'; 7 import 'memory_source_file_helper.dart';
8 8
9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'
10 show NullSink; 10 show NullSink;
11 11
12 import '../../../sdk/lib/_internal/compiler/compiler.dart' 12 import '../../../sdk/lib/_internal/compiler/compiler.dart'
13 show Diagnostic, DiagnosticHandler; 13 show Diagnostic, DiagnosticHandler, CompilerOutputProvider;
14 14
15 import 'dart:async'; 15 import 'dart:async';
16 16
17 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirror s.dart'; 17 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirror s.dart';
18 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.dart' ; 18 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.dart' ;
19 19
20 class DiagnosticMessage { 20 class DiagnosticMessage {
21 final Uri uri; 21 final Uri uri;
22 final int begin; 22 final int begin;
23 final int end; 23 final int end;
(...skipping 28 matching lines...) Expand all
52 52
53 Iterable<DiagnosticMessage> get hints { 53 Iterable<DiagnosticMessage> get hints {
54 return filterMessagesByKind(Diagnostic.HINT); 54 return filterMessagesByKind(Diagnostic.HINT);
55 } 55 }
56 56
57 Iterable<DiagnosticMessage> get infos { 57 Iterable<DiagnosticMessage> get infos {
58 return filterMessagesByKind(Diagnostic.INFO); 58 return filterMessagesByKind(Diagnostic.INFO);
59 } 59 }
60 } 60 }
61 61
62 class BufferedEventSink implements EventSink<String> {
63 StringBuffer sb = new StringBuffer();
64 String text;
65
66 void add(String event) {
67 sb.write(event);
68 }
69
70 void addError(errorEvent, [StackTrace stackTrace]) {
71 // Do not support this.
72 }
73
74 void close() {
75 text = sb.toString();
76 sb = null;
77 }
78 }
79
80 class OutputCollector {
81 Map<String, Map<String, BufferedEventSink>> outputMap = {};
82
83 EventSink<String> call(String name, String extension) {
84 Map<String, BufferedEventSink> sinkMap =
85 outputMap.putIfAbsent(extension, () => {});
86 return sinkMap.putIfAbsent(name, () => new BufferedEventSink());
87 }
88
89 String getOutput(String name, String extension) {
90 Map<String, BufferedEventSink> sinkMap = outputMap[extension];
91 if (sinkMap == null) return null;
92 BufferedEventSink sink = sinkMap[name];
93 return sink != null ? sink.text : null;
94 }
95 }
96
62 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler, 97 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler,
63 SourceFileProvider provider, 98 SourceFileProvider provider,
64 bool showDiagnostics) { 99 bool showDiagnostics) {
65 var handler = diagnosticHandler; 100 var handler = diagnosticHandler;
66 if (showDiagnostics) { 101 if (showDiagnostics) {
67 if (diagnosticHandler == null) { 102 if (diagnosticHandler == null) {
68 handler = new FormattingDiagnosticHandler(provider); 103 handler = new FormattingDiagnosticHandler(provider);
69 } else { 104 } else {
70 var formattingHandler = new FormattingDiagnosticHandler(provider); 105 var formattingHandler = new FormattingDiagnosticHandler(provider);
71 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { 106 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {
72 diagnosticHandler(uri, begin, end, message, kind); 107 diagnosticHandler(uri, begin, end, message, kind);
73 formattingHandler(uri, begin, end, message, kind); 108 formattingHandler(uri, begin, end, message, kind);
74 }; 109 };
75 } 110 }
76 } else if (diagnosticHandler == null) { 111 } else if (diagnosticHandler == null) {
77 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; 112 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {};
78 } 113 }
79 return handler; 114 return handler;
80 } 115 }
81 116
82 Expando<MemorySourceFileProvider> expando = 117 Expando<MemorySourceFileProvider> expando =
83 new Expando<MemorySourceFileProvider>(); 118 new Expando<MemorySourceFileProvider>();
84 119
85 Compiler compilerFor(Map<String,String> memorySourceFiles, 120 Compiler compilerFor(Map<String,String> memorySourceFiles,
86 {DiagnosticHandler diagnosticHandler, 121 {DiagnosticHandler diagnosticHandler,
122 CompilerOutputProvider outputProvider,
87 List<String> options: const [], 123 List<String> options: const [],
88 Compiler cachedCompiler, 124 Compiler cachedCompiler,
89 bool showDiagnostics: true, 125 bool showDiagnostics: true,
90 Uri packageRoot}) { 126 Uri packageRoot}) {
91 Uri libraryRoot = Uri.base.resolve('sdk/'); 127 Uri libraryRoot = Uri.base.resolve('sdk/');
92 Uri script = Uri.base.resolveUri(Platform.script); 128 Uri script = Uri.base.resolveUri(Platform.script);
93 if (packageRoot == null) { 129 if (packageRoot == null) {
94 packageRoot = Uri.base.resolve('${Platform.packageRoot}/'); 130 packageRoot = Uri.base.resolve('${Platform.packageRoot}/');
95 } 131 }
96 132
97 MemorySourceFileProvider provider; 133 MemorySourceFileProvider provider;
98 var readStringFromUri; 134 var readStringFromUri;
99 if (cachedCompiler == null) { 135 if (cachedCompiler == null) {
100 provider = new MemorySourceFileProvider(memorySourceFiles); 136 provider = new MemorySourceFileProvider(memorySourceFiles);
101 readStringFromUri = provider.readStringFromUri; 137 readStringFromUri = provider.readStringFromUri;
102 // Saving the provider in case we need it later for a cached compiler. 138 // Saving the provider in case we need it later for a cached compiler.
103 expando[readStringFromUri] = provider; 139 expando[readStringFromUri] = provider;
104 } else { 140 } else {
105 // When using a cached compiler, it has read a number of files from disk 141 // When using a cached compiler, it has read a number of files from disk
106 // already (and will not attemp to read them again due to caching). These 142 // already (and will not attemp to read them again due to caching). These
107 // files must be available to the new diagnostic handler. 143 // files must be available to the new diagnostic handler.
108 provider = expando[cachedCompiler.provider]; 144 provider = expando[cachedCompiler.provider];
109 readStringFromUri = cachedCompiler.provider; 145 readStringFromUri = cachedCompiler.provider;
110 provider.memorySourceFiles = memorySourceFiles; 146 provider.memorySourceFiles = memorySourceFiles;
111 } 147 }
112 var handler = 148 var handler =
113 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); 149 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
114 150
115 EventSink<String> outputProvider(String name, String extension) { 151 EventSink<String> noOutputProvider(String name, String extension) {
116 if (name != '') throw 'Attempt to output file "$name.$extension"'; 152 if (name != '') throw 'Attempt to output file "$name.$extension"';
117 return new NullSink('$name.$extension'); 153 return new NullSink('$name.$extension');
118 } 154 }
155 if (outputProvider == null) {
156 outputProvider = noOutputProvider;
157 }
119 158
120 Compiler compiler = new Compiler(readStringFromUri, 159 Compiler compiler = new Compiler(readStringFromUri,
121 outputProvider, 160 outputProvider,
122 handler, 161 handler,
123 libraryRoot, 162 libraryRoot,
124 packageRoot, 163 packageRoot,
125 options, 164 options,
126 {}); 165 {});
127 if (cachedCompiler != null) { 166 if (cachedCompiler != null) {
128 compiler.coreLibrary = cachedCompiler.libraries['dart:core']; 167 compiler.coreLibrary = cachedCompiler.libraries['dart:core'];
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); 210 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
172 211
173 List<Uri> libraries = <Uri>[]; 212 List<Uri> libraries = <Uri>[];
174 memorySourceFiles.forEach((String path, _) { 213 memorySourceFiles.forEach((String path, _) {
175 libraries.add(new Uri(scheme: 'memory', path: path)); 214 libraries.add(new Uri(scheme: 'memory', path: path));
176 }); 215 });
177 216
178 return analyze(libraries, libraryRoot, packageRoot, 217 return analyze(libraries, libraryRoot, packageRoot,
179 provider, handler, options); 218 provider, handler, options);
180 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698