OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:front_end/memory_file_system.dart'; | 5 import 'package:front_end/memory_file_system.dart'; |
6 import 'package:front_end/src/base/libraries_specification.dart'; | 6 import 'package:front_end/src/base/libraries_specification.dart'; |
7 | 7 |
8 /// Create SDK libraries which are used by Fasta to perform kernel generation. | 8 final _ASYNC = r''' |
9 /// The root of the SDK is `file:///sdk`, it will contain a libraries | 9 library dart.async; |
10 /// specification file at `lib/libraries.json`. | |
11 /// | |
12 /// Returns the [TargetLibrariesSpecification] whose contents are in | |
13 /// libraries.json. | |
14 TargetLibrariesSpecification createSdkFiles(MemoryFileSystem fileSystem) { | |
15 Map<String, LibraryInfo> dartLibraries = {}; | |
16 void addSdkLibrary(String name, String contents) { | |
17 String path = '$name/$name.dart'; | |
18 Uri uri = Uri.parse('file:///sdk/lib/$path'); | |
19 fileSystem.entityForUri(uri).writeAsStringSync(contents); | |
20 dartLibraries[name] = new LibraryInfo(name, uri, const []); | |
21 } | |
22 | 10 |
23 addSdkLibrary('core', r''' | 11 class Future<T> { |
| 12 factory Future(computation()) => null; |
| 13 factory Future.delayed(Duration duration, [T computation()]) => null; |
| 14 factory Future.microtask(FutureOr<T> computation()) => null; |
| 15 factory Future.value([value]) => null; |
| 16 |
| 17 static Future<List<T>> wait<T>(Iterable<Future<T>> futures) => null; |
| 18 Future<R> then<R>(FutureOr<R> onValue(T value)) => null; |
| 19 |
| 20 Future<T> whenComplete(action()); |
| 21 } |
| 22 |
| 23 |
| 24 class FutureOr<T> {} |
| 25 class Stream<T> {} |
| 26 abstract class StreamIterator<T> {} |
| 27 |
| 28 abstract class Completer<T> { |
| 29 factory Completer() => null; |
| 30 factory Completer.sync() => null; |
| 31 Future<T> get future; |
| 32 void complete([FutureOr<T> value]); |
| 33 void completeError(Object error, [StackTrace stackTrace]); |
| 34 bool get isCompleted; |
| 35 } |
| 36 |
| 37 class _StreamIterator<T> implements StreamIterator<T> {} |
| 38 class _AsyncStarStreamController {} |
| 39 Object _asyncStackTraceHelper(Function async_op) { } |
| 40 Function _asyncThenWrapperHelper(continuation) {} |
| 41 Function _asyncErrorWrapperHelper(continuation) {} |
| 42 Future _awaitHelper( |
| 43 object, Function thenCallback, Function errorCallback, var awaiter) {} |
| 44 '''; |
| 45 |
| 46 final _CORE = r''' |
24 library dart.core; | 47 library dart.core; |
25 import 'dart:_internal'; | 48 import 'dart:_internal'; |
26 import 'dart:async'; | 49 import 'dart:async'; |
27 | 50 |
28 class Object { | 51 class Object { |
29 const Object(); | 52 const Object(); |
30 bool operator ==(other) => identical(this, other); | 53 bool operator ==(other) => identical(this, other); |
31 String toString() => 'a string'; | 54 String toString() => 'a string'; |
32 int get hashCode => 0; | 55 int get hashCode => 0; |
33 Type get runtimeType => null; | 56 Type get runtimeType => null; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 Iterable<V> get values; | 219 Iterable<V> get values; |
197 } | 220 } |
198 | 221 |
199 class Duration implements Comparable<Duration> {} | 222 class Duration implements Comparable<Duration> {} |
200 | 223 |
201 external bool identical(Object a, Object b); | 224 external bool identical(Object a, Object b); |
202 | 225 |
203 void print(Object o) {} | 226 void print(Object o) {} |
204 | 227 |
205 abstract class _SyncIterable implements Iterable {} | 228 abstract class _SyncIterable implements Iterable {} |
206 '''); | 229 '''; |
207 | 230 |
208 addSdkLibrary('async', r''' | 231 /// Create SDK libraries which are used by Fasta to perform kernel generation. |
209 library dart.async; | 232 /// The root of the SDK is `file:///sdk`, it will contain a libraries |
| 233 /// specification file at `lib/libraries.json`. |
| 234 /// |
| 235 /// Returns the [TargetLibrariesSpecification] whose contents are in |
| 236 /// libraries.json. |
| 237 TargetLibrariesSpecification createSdkFiles(MemoryFileSystem fileSystem) { |
| 238 Map<String, LibraryInfo> dartLibraries = {}; |
| 239 void addSdkLibrary(String name, String contents) { |
| 240 String path = '$name/$name.dart'; |
| 241 Uri uri = Uri.parse('file:///sdk/lib/$path'); |
| 242 fileSystem.entityForUri(uri).writeAsStringSync(contents); |
| 243 dartLibraries[name] = new LibraryInfo(name, uri, const []); |
| 244 } |
210 | 245 |
211 class Future<T> { | 246 fileSystem.entityForUri(Uri.parse('file:///sdk/')).createDirectory(); |
212 factory Future(computation()) => null; | |
213 factory Future.delayed(Duration duration, [T computation()]) => null; | |
214 factory Future.microtask(FutureOr<T> computation()) => null; | |
215 factory Future.value([value]) => null; | |
216 | 247 |
217 static Future<List<T>> wait<T>(Iterable<Future<T>> futures) => null; | 248 addSdkLibrary('core', _CORE); |
218 Future<R> then<R>(FutureOr<R> onValue(T value)) => null; | 249 addSdkLibrary('async', _ASYNC); |
219 | |
220 Future<T> whenComplete(action()); | |
221 } | |
222 | |
223 | |
224 class FutureOr<T> {} | |
225 class Stream<T> {} | |
226 abstract class StreamIterator<T> {} | |
227 | |
228 abstract class Completer<T> { | |
229 factory Completer() => null; | |
230 factory Completer.sync() => null; | |
231 Future<T> get future; | |
232 void complete([FutureOr<T> value]); | |
233 void completeError(Object error, [StackTrace stackTrace]); | |
234 bool get isCompleted; | |
235 } | |
236 | |
237 class _StreamIterator<T> implements StreamIterator<T> {} | |
238 class _AsyncStarStreamController {} | |
239 Object _asyncStackTraceHelper(Function async_op) { } | |
240 Function _asyncThenWrapperHelper(continuation) {} | |
241 Function _asyncErrorWrapperHelper(continuation) {} | |
242 Future _awaitHelper( | |
243 object, Function thenCallback, Function errorCallback, var awaiter) {} | |
244 '''); | |
245 | 250 |
246 addSdkLibrary('collection', 'library dart.collection;'); | 251 addSdkLibrary('collection', 'library dart.collection;'); |
247 addSdkLibrary('convert', 'library dart.convert;'); | 252 addSdkLibrary('convert', 'library dart.convert;'); |
248 addSdkLibrary('developer', 'library dart.developer;'); | 253 addSdkLibrary('developer', 'library dart.developer;'); |
249 addSdkLibrary('io', 'library dart.io;'); | 254 addSdkLibrary('io', 'library dart.io;'); |
250 addSdkLibrary('isolate', 'library dart.isolate;'); | 255 addSdkLibrary('isolate', 'library dart.isolate;'); |
251 addSdkLibrary('math', ''' | 256 addSdkLibrary('math', ''' |
252 library dart.math; | 257 library dart.math; |
253 external double sin(num radians); | 258 external double sin(num radians); |
254 '''); | 259 '''); |
255 addSdkLibrary('mirrors', 'library dart.mirrors;'); | 260 addSdkLibrary('mirrors', 'library dart.mirrors;'); |
256 addSdkLibrary('nativewrappers', 'library dart.nativewrappers;'); | 261 addSdkLibrary('nativewrappers', 'library dart.nativewrappers;'); |
257 addSdkLibrary('profiler', 'library dart.profiler;'); | 262 addSdkLibrary('profiler', 'library dart.profiler;'); |
258 addSdkLibrary('typed_data', 'library dart.typed_data;'); | 263 addSdkLibrary('typed_data', 'library dart.typed_data;'); |
259 addSdkLibrary('vmservice_io', 'library dart.vmservice_io;'); | |
260 addSdkLibrary('_builtin', 'library dart._builtin;'); | 264 addSdkLibrary('_builtin', 'library dart._builtin;'); |
261 addSdkLibrary('_internal', ''' | 265 addSdkLibrary('_internal', ''' |
262 library dart._internal; | 266 library dart._internal; |
263 class Symbol {} | 267 class Symbol {} |
264 class ExternalName { | 268 class ExternalName { |
265 final String name; | 269 final String name; |
266 const ExternalName(this.name); | 270 const ExternalName(this.name); |
267 } | 271 } |
268 '''); | 272 '''); |
269 addSdkLibrary('_vmservice', 'library dart._vmservice;'); | |
270 | 273 |
271 var targetSpec = new TargetLibrariesSpecification('vm', dartLibraries); | 274 var targetSpec = new TargetLibrariesSpecification(null, dartLibraries); |
272 var spec = new LibrariesSpecification({'vm': targetSpec}); | 275 var spec = new LibrariesSpecification({'none': targetSpec, 'vm': targetSpec}); |
273 | 276 |
274 Uri uri = Uri.parse('file:///sdk/lib/libraries.json'); | 277 Uri uri = Uri.parse('file:///sdk/lib/libraries.json'); |
275 fileSystem.entityForUri(uri).writeAsStringSync(spec.toJsonString(uri)); | 278 fileSystem.entityForUri(uri).writeAsStringSync(spec.toJsonString(uri)); |
276 return targetSpec; | 279 return targetSpec; |
277 } | 280 } |
OLD | NEW |