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

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

Issue 21544003: Handle missing imports/exports/parts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 'package:expect/expect.dart'; 7 import 'package:expect/expect.dart';
8 import 'memory_source_file_helper.dart'; 8 import 'memory_source_file_helper.dart';
9 9
10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'
11 show NullSink; 11 show NullSink;
12 12
13 import '../../../sdk/lib/_internal/compiler/compiler.dart' 13 import '../../../sdk/lib/_internal/compiler/compiler.dart'
14 show DiagnosticHandler; 14 show Diagnostic, DiagnosticHandler;
15 15
16 import 'dart:async'; 16 import 'dart:async';
17 17
18 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; 18 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ;
19 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart'; 19 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart';
20 20
21 class DiagnosticMessage {
22 final Uri uri;
23 final int begin;
24 final int end;
25 final String message;
26 final Diagnostic kind;
27
28 DiagnosticMessage(this.uri, this.begin, this.end, this.message, this.kind);
29 }
30
31 class DiagnosticCollector {
32 List<DiagnosticMessage> messages = <DiagnosticMessage>[];
33
34 void call(Uri uri, int begin, int end, String message,
35 Diagnostic kind) {
36 messages.add(new DiagnosticMessage(uri, begin, end, message, kind));
37 }
38
39 Iterable<DiagnosticMessage> filterMessagesByKind(Diagnostic kind) {
40 return messages.where(
41 (DiagnosticMessage message) => message.kind == kind);
42 }
43
44 Iterable<DiagnosticMessage> get errors {
45 return filterMessagesByKind(Diagnostic.ERROR);
46 }
47
48 Iterable<DiagnosticMessage> get warnings {
49 return filterMessagesByKind(Diagnostic.WARNING);
50 }
51
52 Iterable<DiagnosticMessage> get hints {
53 return filterMessagesByKind(Diagnostic.HINT);
54 }
55 }
56
57 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler,
58 SourceFileProvider provider,
59 bool showDiagnostics) {
60 var handler = diagnosticHandler;
61 if (showDiagnostics) {
62 if (diagnosticHandler == null) {
63 handler = new FormattingDiagnosticHandler(provider);
64 } else {
65 var formattingHandler = new FormattingDiagnosticHandler(provider);
66 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {
67 diagnosticHandler(uri, begin, end, message, kind);
68 formattingHandler(uri, begin, end, message, kind);
69 };
70 }
71 } else if (diagnosticHandler == null) {
72 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {};
73 }
74 return handler;
75 }
76
21 Compiler compilerFor(Map<String,String> memorySourceFiles, 77 Compiler compilerFor(Map<String,String> memorySourceFiles,
22 {DiagnosticHandler diagnosticHandler, 78 {DiagnosticHandler diagnosticHandler,
23 List<String> options: const []}) { 79 List<String> options: const [],
80 bool showDiagnostics: true}) {
24 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); 81 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script));
25 Uri libraryRoot = script.resolve('../../../sdk/'); 82 Uri libraryRoot = script.resolve('../../../sdk/');
26 Uri packageRoot = script.resolve('./packages/'); 83 Uri packageRoot = script.resolve('./packages/');
27 84
28 MemorySourceFileProvider.MEMORY_SOURCE_FILES = memorySourceFiles; 85 MemorySourceFileProvider.MEMORY_SOURCE_FILES = memorySourceFiles;
29 var provider = new MemorySourceFileProvider(); 86 var provider = new MemorySourceFileProvider();
30 if (diagnosticHandler == null) { 87 var handler =
31 diagnosticHandler = new FormattingDiagnosticHandler(provider); 88 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
32 }
33 89
34 EventSink<String> outputProvider(String name, String extension) { 90 EventSink<String> outputProvider(String name, String extension) {
35 if (name != '') throw 'Attempt to output file "$name.$extension"'; 91 if (name != '') throw 'Attempt to output file "$name.$extension"';
36 return new NullSink('$name.$extension'); 92 return new NullSink('$name.$extension');
37 } 93 }
38 94
39 Compiler compiler = new Compiler(provider.readStringFromUri, 95 Compiler compiler = new Compiler(provider,
40 outputProvider, 96 outputProvider,
41 diagnosticHandler, 97 handler,
42 libraryRoot, 98 libraryRoot,
43 packageRoot, 99 packageRoot,
44 options); 100 options);
45 return compiler; 101 return compiler;
46 } 102 }
47 103
48 Future<MirrorSystem> mirrorSystemFor(Map<String,String> memorySourceFiles, 104 Future<MirrorSystem> mirrorSystemFor(Map<String,String> memorySourceFiles,
49 {DiagnosticHandler diagnosticHandler, 105 {DiagnosticHandler diagnosticHandler,
50 List<String> options: const []}) { 106 List<String> options: const [],
107 bool showDiagnostics: true}) {
51 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); 108 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script));
52 Uri libraryRoot = script.resolve('../../../sdk/'); 109 Uri libraryRoot = script.resolve('../../../sdk/');
53 Uri packageRoot = script.resolve('./packages/'); 110 Uri packageRoot = script.resolve('./packages/');
54 111
55 MemorySourceFileProvider.MEMORY_SOURCE_FILES = memorySourceFiles; 112 MemorySourceFileProvider.MEMORY_SOURCE_FILES = memorySourceFiles;
56 var provider = new MemorySourceFileProvider(); 113 var provider = new MemorySourceFileProvider();
57 if (diagnosticHandler == null) { 114 var handler =
58 diagnosticHandler = new FormattingDiagnosticHandler(provider); 115 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
59 }
60 116
61 List<Uri> libraries = <Uri>[]; 117 List<Uri> libraries = <Uri>[];
62 memorySourceFiles.forEach((String path, _) { 118 memorySourceFiles.forEach((String path, _) {
63 libraries.add(new Uri(scheme: 'memory', path: path)); 119 libraries.add(new Uri(scheme: 'memory', path: path));
64 }); 120 });
65 121
66 return analyze(libraries, libraryRoot, packageRoot, 122 return analyze(libraries, libraryRoot, packageRoot,
67 provider, diagnosticHandler, options); 123 provider, handler, options);
68 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698