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

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: Too many changes to summarize in one line. 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 trydart.caching_compiler;
6 6
7 import 'memory_source_file_helper.dart'; 7 import 'package:compiler/compiler.dart' show
kasperl 2014/03/24 10:32:51 This is "weird" file. Maybe add a comment that exp
ahe 2014/03/24 15:20:23 Done.
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 abstract class SourceFileProvider {}
13 show Diagnostic, DiagnosticHandler, CompilerOutputProvider; 16 class FormattingDiagnosticHandler {
14 17 FormattingDiagnosticHandler(a);
15 import 'dart:async';
16
17 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirror s.dart';
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 } 18 }
31 19 abstract class Platform {
32 class DiagnosticCollector { 20 static var script;
33 List<DiagnosticMessage> messages = <DiagnosticMessage>[]; 21 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 } 22 }
61 23 class MemorySourceFileProvider extends SourceFileProvider {
62 class BufferedEventSink implements EventSink<String> { 24 var readStringFromUri;
63 StringBuffer sb = new StringBuffer(); 25 var memorySourceFiles;
64 String text; 26 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 } 27 }
79 28 class NullSink extends EventSink {
80 class OutputCollector { 29 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 } 30 }
31 var expando;
32 abstract class EventSink<T> {}
96 33
97 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler, 34 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler,
98 SourceFileProvider provider, 35 SourceFileProvider provider,
99 bool showDiagnostics) { 36 bool showDiagnostics) {
100 var handler = diagnosticHandler; 37 var handler = diagnosticHandler;
101 if (showDiagnostics) { 38 if (showDiagnostics) {
102 if (diagnosticHandler == null) { 39 if (diagnosticHandler == null) {
103 handler = new FormattingDiagnosticHandler(provider); 40 handler = new FormattingDiagnosticHandler(provider);
104 } else { 41 } else {
105 var formattingHandler = new FormattingDiagnosticHandler(provider); 42 var formattingHandler = new FormattingDiagnosticHandler(provider);
106 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { 43 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {
107 diagnosticHandler(uri, begin, end, message, kind); 44 diagnosticHandler(uri, begin, end, message, kind);
108 formattingHandler(uri, begin, end, message, kind); 45 formattingHandler(uri, begin, end, message, kind);
109 }; 46 };
110 } 47 }
111 } else if (diagnosticHandler == null) { 48 } else if (diagnosticHandler == null) {
112 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; 49 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {};
113 } 50 }
114 return handler; 51 return handler;
115 } 52 }
116 53
117 Expando<MemorySourceFileProvider> expando =
118 new Expando<MemorySourceFileProvider>();
119
120 Compiler compilerFor(Map<String,String> memorySourceFiles, 54 Compiler compilerFor(Map<String,String> memorySourceFiles,
121 {DiagnosticHandler diagnosticHandler, 55 {DiagnosticHandler diagnosticHandler,
122 CompilerOutputProvider outputProvider, 56 CompilerOutputProvider outputProvider,
123 List<String> options: const [], 57 List<String> options: const [],
124 Compiler cachedCompiler, 58 Compiler cachedCompiler,
125 bool showDiagnostics: true, 59 bool showDiagnostics: true,
126 Uri packageRoot}) { 60 Uri packageRoot}) {
127 Uri libraryRoot = Uri.base.resolve('sdk/'); 61 Uri libraryRoot = Uri.base.resolve('sdk/');
128 Uri script = Uri.base.resolveUri(Platform.script); 62 Uri script = Uri.base.resolveUri(Platform.script);
129 if (packageRoot == null) { 63 if (packageRoot == null) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 cachedCompiler.enqueuer.resolution.resolvedElements; 123 cachedCompiler.enqueuer.resolution.resolvedElements;
190 cachedTreeElements.forEach((element, treeElements) { 124 cachedTreeElements.forEach((element, treeElements) {
191 if (element.getLibrary().isPlatformLibrary) { 125 if (element.getLibrary().isPlatformLibrary) {
192 compiler.enqueuer.resolution.resolvedElements[element] = 126 compiler.enqueuer.resolution.resolvedElements[element] =
193 treeElements; 127 treeElements;
194 } 128 }
195 }); 129 });
196 } 130 }
197 return compiler; 131 return compiler;
198 } 132 }
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

Powered by Google App Engine
This is Rietveld 408576698