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

Side by Side Diff: dart/site/try/src/caching_compiler.dart

Issue 197923002: Mock up code completion. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r34309. 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
« no previous file with comments | « dart/site/try/src/Makefile ('k') | dart/site/try/src/compilation.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) 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 trydart.caching_compiler;
6 6
7 import 'memory_source_file_helper.dart'; 7 import 'package:compiler/compiler.dart' show
8 CompilerOutputProvider,
9 Diagnostic,
10 DiagnosticHandler;
8 11
9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' 12 import 'package:compiler/implementation/apiimpl.dart' show
10 show NullSink; 13 Compiler;
11 14
12 import '../../../sdk/lib/_internal/compiler/compiler.dart' 15 // This file is copied from a dart2js test which uses dart:io. For now, mock up
13 show Diagnostic, DiagnosticHandler, CompilerOutputProvider; 16 // a bunch of interfaces to silence the analyzer. This file will serve as basis
14 17 // for incremental analysis.
15 import 'dart:async'; 18 abstract class SourceFileProvider {}
16 19 class FormattingDiagnosticHandler {
17 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirror s.dart'; 20 FormattingDiagnosticHandler(a);
18 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.dart' ;
19
20 class DiagnosticMessage {
21 final Uri uri;
22 final int begin;
23 final int end;
24 final String message;
25 final Diagnostic kind;
26
27 DiagnosticMessage(this.uri, this.begin, this.end, this.message, this.kind);
28
29 String toString() => '$uri:$begin:$end:$message:$kind';
30 } 21 }
31 22 abstract class Platform {
32 class DiagnosticCollector { 23 static var script;
33 List<DiagnosticMessage> messages = <DiagnosticMessage>[]; 24 static var packageRoot;
34
35 void call(Uri uri, int begin, int end, String message,
36 Diagnostic kind) {
37 messages.add(new DiagnosticMessage(uri, begin, end, message, kind));
38 }
39
40 Iterable<DiagnosticMessage> filterMessagesByKind(Diagnostic kind) {
41 return messages.where(
42 (DiagnosticMessage message) => message.kind == kind);
43 }
44
45 Iterable<DiagnosticMessage> get errors {
46 return filterMessagesByKind(Diagnostic.ERROR);
47 }
48
49 Iterable<DiagnosticMessage> get warnings {
50 return filterMessagesByKind(Diagnostic.WARNING);
51 }
52
53 Iterable<DiagnosticMessage> get hints {
54 return filterMessagesByKind(Diagnostic.HINT);
55 }
56
57 Iterable<DiagnosticMessage> get infos {
58 return filterMessagesByKind(Diagnostic.INFO);
59 }
60 } 25 }
61 26 class MemorySourceFileProvider extends SourceFileProvider {
62 class BufferedEventSink implements EventSink<String> { 27 var readStringFromUri;
63 StringBuffer sb = new StringBuffer(); 28 var memorySourceFiles;
64 String text; 29 MemorySourceFileProvider(a);
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 } 30 }
79 31 class NullSink extends EventSink {
80 class OutputCollector { 32 NullSink(a);
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 } 33 }
34 var expando;
35 abstract class EventSink<T> {}
96 36
97 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler, 37 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler,
98 SourceFileProvider provider, 38 SourceFileProvider provider,
99 bool showDiagnostics) { 39 bool showDiagnostics) {
100 var handler = diagnosticHandler; 40 var handler = diagnosticHandler;
101 if (showDiagnostics) { 41 if (showDiagnostics) {
102 if (diagnosticHandler == null) { 42 if (diagnosticHandler == null) {
103 handler = new FormattingDiagnosticHandler(provider); 43 handler = new FormattingDiagnosticHandler(provider);
104 } else { 44 } else {
105 var formattingHandler = new FormattingDiagnosticHandler(provider); 45 var formattingHandler = new FormattingDiagnosticHandler(provider);
106 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { 46 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {
107 diagnosticHandler(uri, begin, end, message, kind); 47 diagnosticHandler(uri, begin, end, message, kind);
108 formattingHandler(uri, begin, end, message, kind); 48 formattingHandler(uri, begin, end, message, kind);
109 }; 49 };
110 } 50 }
111 } else if (diagnosticHandler == null) { 51 } else if (diagnosticHandler == null) {
112 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; 52 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {};
113 } 53 }
114 return handler; 54 return handler;
115 } 55 }
116 56
117 Expando<MemorySourceFileProvider> expando =
118 new Expando<MemorySourceFileProvider>();
119
120 Compiler compilerFor(Map<String,String> memorySourceFiles, 57 Compiler compilerFor(Map<String,String> memorySourceFiles,
121 {DiagnosticHandler diagnosticHandler, 58 {DiagnosticHandler diagnosticHandler,
122 CompilerOutputProvider outputProvider, 59 CompilerOutputProvider outputProvider,
123 List<String> options: const [], 60 List<String> options: const [],
124 Compiler cachedCompiler, 61 Compiler cachedCompiler,
125 bool showDiagnostics: true, 62 bool showDiagnostics: true,
126 Uri packageRoot}) { 63 Uri packageRoot}) {
127 Uri libraryRoot = Uri.base.resolve('sdk/'); 64 Uri libraryRoot = Uri.base.resolve('sdk/');
128 Uri script = Uri.base.resolveUri(Platform.script); 65 Uri script = Uri.base.resolveUri(Platform.script);
129 if (packageRoot == null) { 66 if (packageRoot == null) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 cachedCompiler.enqueuer.resolution.resolvedElements; 126 cachedCompiler.enqueuer.resolution.resolvedElements;
190 cachedTreeElements.forEach((element, treeElements) { 127 cachedTreeElements.forEach((element, treeElements) {
191 if (element.getLibrary().isPlatformLibrary) { 128 if (element.getLibrary().isPlatformLibrary) {
192 compiler.enqueuer.resolution.resolvedElements[element] = 129 compiler.enqueuer.resolution.resolvedElements[element] =
193 treeElements; 130 treeElements;
194 } 131 }
195 }); 132 });
196 } 133 }
197 return compiler; 134 return compiler;
198 } 135 }
199
200 Future<MirrorSystem> mirrorSystemFor(Map<String,String> memorySourceFiles,
201 {DiagnosticHandler diagnosticHandler,
202 List<String> options: const [],
203 bool showDiagnostics: true}) {
204 Uri libraryRoot = Uri.base.resolve('sdk/');
205 Uri packageRoot = Uri.base.resolve('${Platform.packageRoot}/');
206 Uri script = Uri.base.resolveUri(Platform.script);
207
208 var provider = new MemorySourceFileProvider(memorySourceFiles);
209 var handler =
210 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
211
212 List<Uri> libraries = <Uri>[];
213 memorySourceFiles.forEach((String path, _) {
214 libraries.add(new Uri(scheme: 'memory', path: path));
215 });
216
217 return analyze(libraries, libraryRoot, packageRoot,
218 provider, handler, options);
219 }
OLDNEW
« no previous file with comments | « dart/site/try/src/Makefile ('k') | dart/site/try/src/compilation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698