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

Side by Side Diff: tests/compiler/dart2js/sourcemaps/sourcemap_helper.dart

Issue 2690063002: Refactor CompilerOutput (Closed)
Patch Set: Updated cf. comments Created 3 years, 10 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
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 sourcemap.helper; 5 library sourcemap.helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'package:compiler/compiler_new.dart'; 9 import 'package:compiler/compiler_new.dart';
10 import 'package:compiler/src/apiimpl.dart' as api; 10 import 'package:compiler/src/apiimpl.dart' as api;
11 import 'package:compiler/src/commandline_options.dart'; 11 import 'package:compiler/src/commandline_options.dart';
12 import 'package:compiler/src/null_compiler_output.dart' show NullSink; 12 import 'package:compiler/src/null_compiler_output.dart' show NullSink;
13 import 'package:compiler/src/elements/elements.dart'; 13 import 'package:compiler/src/elements/elements.dart';
14 import 'package:compiler/src/helpers/helpers.dart'; 14 import 'package:compiler/src/helpers/helpers.dart';
15 import 'package:compiler/src/filenames.dart'; 15 import 'package:compiler/src/filenames.dart';
16 import 'package:compiler/src/io/code_output.dart'; 16 import 'package:compiler/src/io/code_output.dart';
17 import 'package:compiler/src/io/source_file.dart'; 17 import 'package:compiler/src/io/source_file.dart';
18 import 'package:compiler/src/io/source_information.dart'; 18 import 'package:compiler/src/io/source_information.dart';
19 import 'package:compiler/src/io/position_information.dart'; 19 import 'package:compiler/src/io/position_information.dart';
20 import 'package:compiler/src/js/js.dart' as js; 20 import 'package:compiler/src/js/js.dart' as js;
21 import 'package:compiler/src/js/js_debug.dart'; 21 import 'package:compiler/src/js/js_debug.dart';
22 import 'package:compiler/src/js/js_source_mapping.dart'; 22 import 'package:compiler/src/js/js_source_mapping.dart';
23 import 'package:compiler/src/js_backend/js_backend.dart'; 23 import 'package:compiler/src/js_backend/js_backend.dart';
24 import 'package:compiler/src/source_file_provider.dart'; 24 import 'package:compiler/src/source_file_provider.dart';
25 import '../memory_compiler.dart'; 25 import '../memory_compiler.dart';
26 import '../output_collector.dart'; 26 import '../output_collector.dart';
27 27
28 class SourceFileSink implements EventSink<String> { 28 class SourceFileSink implements OutputSink {
29 final String filename; 29 final String filename;
30 StringBuffer sb = new StringBuffer(); 30 StringBuffer sb = new StringBuffer();
31 SourceFile sourceFile; 31 SourceFile sourceFile;
32 32
33 SourceFileSink(this.filename); 33 SourceFileSink(this.filename);
34 34
35 @override 35 @override
36 void add(String event) { 36 void add(String event) {
37 sb.write(event); 37 sb.write(event);
38 } 38 }
39 39
40 @override 40 @override
41 void addError(errorEvent, [StackTrace stackTrace]) {
42 // Ignore.
43 }
44
45 @override
46 void close() { 41 void close() {
47 sourceFile = new StringSourceFile.fromName(filename, sb.toString()); 42 sourceFile = new StringSourceFile.fromName(filename, sb.toString());
48 } 43 }
49 } 44 }
50 45
51 class OutputProvider implements CompilerOutput { 46 class OutputProvider implements CompilerOutput {
52 Map<Uri, SourceFileSink> outputMap = <Uri, SourceFileSink>{}; 47 Map<Uri, SourceFileSink> outputMap = <Uri, SourceFileSink>{};
53 48
54 SourceFile getSourceFile(Uri uri) { 49 SourceFile getSourceFile(Uri uri) {
55 SourceFileSink sink = outputMap[uri]; 50 SourceFileSink sink = outputMap[uri];
56 if (sink != null) { 51 if (sink != null) {
57 return sink.sourceFile; 52 return sink.sourceFile;
58 } 53 }
59 return null; 54 return null;
60 } 55 }
61 56
62 SourceFileSink createSourceFileSink(String name, String extension) { 57 SourceFileSink createSourceFileSink(
58 String name, String extension, OutputType type) {
63 String filename = '$name.$extension'; 59 String filename = '$name.$extension';
64 SourceFileSink sink = new SourceFileSink(filename); 60 SourceFileSink sink = new SourceFileSink(filename);
65 Uri uri = Uri.parse(filename); 61 Uri uri = Uri.parse(filename);
66 outputMap[uri] = sink; 62 outputMap[uri] = sink;
67 return sink; 63 return sink;
68 } 64 }
69 65
70 @override 66 @override
71 EventSink<String> createEventSink(String name, String extension) { 67 OutputSink createOutputSink(String name, String extension, OutputType type) {
72 return createSourceFileSink(name, extension); 68 return createSourceFileSink(name, extension, type);
73 } 69 }
74 } 70 }
75 71
76 class CloningOutputProvider extends OutputProvider { 72 class CloningOutputProvider extends OutputProvider {
77 RandomAccessFileOutputProvider outputProvider; 73 RandomAccessFileOutputProvider outputProvider;
78 74
79 CloningOutputProvider(Uri jsUri, Uri jsMapUri) 75 CloningOutputProvider(Uri jsUri, Uri jsMapUri)
80 : outputProvider = new RandomAccessFileOutputProvider(jsUri, jsMapUri); 76 : outputProvider = new RandomAccessFileOutputProvider(jsUri, jsMapUri);
81 77
82 @override 78 @override
83 EventSink<String> createEventSink(String name, String extension) { 79 OutputSink createOutputSink(String name, String extension, OutputType type) {
84 EventSink<String> output = outputProvider(name, extension); 80 OutputSink output = outputProvider.createOutputSink(name, extension, type);
85 return new CloningEventSink( 81 return new CloningOutputSink(
86 [output, createSourceFileSink(name, extension)]); 82 [output, createSourceFileSink(name, extension, type)]);
87 } 83 }
88 } 84 }
89 85
90 abstract class SourceFileManager { 86 abstract class SourceFileManager {
91 SourceFile getSourceFile(var uri); 87 SourceFile getSourceFile(var uri);
92 } 88 }
93 89
94 class ProviderSourceFileManager implements SourceFileManager { 90 class ProviderSourceFileManager implements SourceFileManager {
95 final SourceFileProvider sourceFileProvider; 91 final SourceFileProvider sourceFileProvider;
96 final OutputProvider outputProvider; 92 final OutputProvider outputProvider;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 absoluteUri = base.resolveUri(uri); 546 absoluteUri = base.resolveUri(uri);
551 } else { 547 } else {
552 absoluteUri = base.resolve(uri); 548 absoluteUri = base.resolve(uri);
553 } 549 }
554 return sourceFiles.putIfAbsent(absoluteUri, () { 550 return sourceFiles.putIfAbsent(absoluteUri, () {
555 String text = new File.fromUri(absoluteUri).readAsStringSync(); 551 String text = new File.fromUri(absoluteUri).readAsStringSync();
556 return new StringSourceFile.fromUri(absoluteUri, text); 552 return new StringSourceFile.fromUri(absoluteUri, text);
557 }); 553 });
558 } 554 }
559 } 555 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/sourcemaps/nomapping_test.dart ('k') | tests/compiler/dart2js/unused_empty_map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698