OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 // This code was auto-generated, is not intended to be edited, and is subject to | |
6 // significant change. Please see the README file for more information. | |
7 | |
8 library engine.sdk; | |
9 | |
10 import 'dart:collection'; | |
11 | |
12 import 'ast.dart'; | |
13 import 'engine.dart' show AnalysisContext; | |
14 import 'source.dart' show ContentCache, Source, UriKind; | |
15 | |
16 /** | |
17 * A Dart SDK installed in a specified location. | |
18 */ | |
19 abstract class DartSdk { | |
20 /** | |
21 * The short name of the dart SDK 'async' library. | |
22 */ | |
23 static final String DART_ASYNC = "dart:async"; | |
24 | |
25 /** | |
26 * The short name of the dart SDK 'core' library. | |
27 */ | |
28 static final String DART_CORE = "dart:core"; | |
29 | |
30 /** | |
31 * The short name of the dart SDK 'html' library. | |
32 */ | |
33 static final String DART_HTML = "dart:html"; | |
34 | |
35 /** | |
36 * The version number that is returned when the real version number could not | |
37 * be determined. | |
38 */ | |
39 static final String DEFAULT_VERSION = "0"; | |
40 | |
41 /** | |
42 * Return the analysis context used for all of the sources in this [DartSdk]. | |
43 */ | |
44 AnalysisContext get context; | |
45 | |
46 /** | |
47 * Return a list containing all of the libraries defined in this SDK. | |
48 */ | |
49 List<SdkLibrary> get sdkLibraries; | |
50 | |
51 /** | |
52 * Return the revision number of this SDK, or `"0"` if the revision number | |
53 * cannot be discovered. | |
54 */ | |
55 String get sdkVersion; | |
56 | |
57 /** | |
58 * Return a list containing the library URI's for the libraries defined in | |
59 * this SDK. | |
60 */ | |
61 List<String> get uris; | |
62 | |
63 /** | |
64 * Return a source representing the given 'file:' [uri] if the file is in this | |
65 * SDK, or `null` if the file is not in this SDK. | |
66 */ | |
67 Source fromFileUri(Uri uri); | |
68 | |
69 /** | |
70 * Return the library representing the library with the given 'dart:' [uri], | |
71 * or `null` if the given URI does not denote a library in this SDK. | |
72 */ | |
73 SdkLibrary getSdkLibrary(String uri); | |
74 | |
75 /** | |
76 * Return the source representing the library with the given 'dart:' [uri], or | |
77 * `null` if the given URI does not denote a library in this SDK. | |
78 */ | |
79 Source mapDartUri(String uri); | |
80 } | |
81 | |
82 /** | |
83 * A map from Dart library URI's to the [SdkLibraryImpl] representing that | |
84 * library. | |
85 */ | |
86 class LibraryMap { | |
87 /** | |
88 * A table mapping Dart library URI's to the library. | |
89 */ | |
90 HashMap<String, SdkLibraryImpl> _libraryMap = | |
91 new HashMap<String, SdkLibraryImpl>(); | |
92 | |
93 /** | |
94 * Return a list containing all of the sdk libraries in this mapping. | |
95 */ | |
96 List<SdkLibrary> get sdkLibraries => new List.from(_libraryMap.values); | |
97 | |
98 /** | |
99 * Return a list containing the library URI's for which a mapping is available
. | |
100 */ | |
101 List<String> get uris => new List.from(_libraryMap.keys.toSet()); | |
102 | |
103 /** | |
104 * Return the library with the given 'dart:' [uri], or `null` if the URI does | |
105 * not map to a library. | |
106 */ | |
107 SdkLibrary getLibrary(String uri) => _libraryMap[uri]; | |
108 | |
109 /** | |
110 * Set the library with the given 'dart:' [uri] to the given [library]. | |
111 */ | |
112 void setLibrary(String dartUri, SdkLibraryImpl library) { | |
113 _libraryMap[dartUri] = library; | |
114 } | |
115 | |
116 /** | |
117 * Return the number of library URI's for which a mapping is available. | |
118 */ | |
119 int size() => _libraryMap.length; | |
120 } | |
121 | |
122 class SdkLibrariesReader_LibraryBuilder extends RecursiveAstVisitor<Object> { | |
123 /** | |
124 * The prefix added to the name of a library to form the URI used in code to | |
125 * reference the library. | |
126 */ | |
127 static String _LIBRARY_PREFIX = "dart:"; | |
128 | |
129 /** | |
130 * The name of the optional parameter used to indicate whether the library is | |
131 * an implementation library. | |
132 */ | |
133 static String _IMPLEMENTATION = "implementation"; | |
134 | |
135 /** | |
136 * The name of the optional parameter used to specify the path used when | |
137 * compiling for dart2js. | |
138 */ | |
139 static String _DART2JS_PATH = "dart2jsPath"; | |
140 | |
141 /** | |
142 * The name of the optional parameter used to indicate whether the library is | |
143 * documented. | |
144 */ | |
145 static String _DOCUMENTED = "documented"; | |
146 | |
147 /** | |
148 * The name of the optional parameter used to specify the category of the | |
149 * library. | |
150 */ | |
151 static String _CATEGORY = "category"; | |
152 | |
153 /** | |
154 * The name of the optional parameter used to specify the platforms on which | |
155 * the library can be used. | |
156 */ | |
157 static String _PLATFORMS = "platforms"; | |
158 | |
159 /** | |
160 * The value of the [PLATFORMS] parameter used to specify that the library can | |
161 * be used on the VM. | |
162 */ | |
163 static String _VM_PLATFORM = "VM_PLATFORM"; | |
164 | |
165 /** | |
166 * A flag indicating whether the dart2js path should be used when it is | |
167 * available. | |
168 */ | |
169 final bool _useDart2jsPaths; | |
170 | |
171 /** | |
172 * The library map that is populated by visiting the AST structure parsed from | |
173 * the contents of the libraries file. | |
174 */ | |
175 LibraryMap _librariesMap = new LibraryMap(); | |
176 | |
177 /** | |
178 * Initialize a newly created library builder to use the dart2js path if | |
179 * [_useDart2jsPaths] is `true`. | |
180 */ | |
181 SdkLibrariesReader_LibraryBuilder(this._useDart2jsPaths); | |
182 | |
183 /** | |
184 * Return the library map that was populated by visiting the AST structure | |
185 * parsed from the contents of the libraries file. | |
186 */ | |
187 LibraryMap get librariesMap => _librariesMap; | |
188 | |
189 @override | |
190 Object visitMapLiteralEntry(MapLiteralEntry node) { | |
191 String libraryName = null; | |
192 Expression key = node.key; | |
193 if (key is SimpleStringLiteral) { | |
194 libraryName = "$_LIBRARY_PREFIX${key.value}"; | |
195 } | |
196 Expression value = node.value; | |
197 if (value is InstanceCreationExpression) { | |
198 SdkLibraryImpl library = new SdkLibraryImpl(libraryName); | |
199 List<Expression> arguments = value.argumentList.arguments; | |
200 for (Expression argument in arguments) { | |
201 if (argument is SimpleStringLiteral) { | |
202 library.path = argument.value; | |
203 } else if (argument is NamedExpression) { | |
204 String name = argument.name.label.name; | |
205 Expression expression = argument.expression; | |
206 if (name == _CATEGORY) { | |
207 library.category = (expression as SimpleStringLiteral).value; | |
208 } else if (name == _IMPLEMENTATION) { | |
209 library.implementation = (expression as BooleanLiteral).value; | |
210 } else if (name == _DOCUMENTED) { | |
211 library.documented = (expression as BooleanLiteral).value; | |
212 } else if (name == _PLATFORMS) { | |
213 if (expression is SimpleIdentifier) { | |
214 String identifier = expression.name; | |
215 if (identifier == _VM_PLATFORM) { | |
216 library.setVmLibrary(); | |
217 } else { | |
218 library.setDart2JsLibrary(); | |
219 } | |
220 } | |
221 } else if (_useDart2jsPaths && name == _DART2JS_PATH) { | |
222 if (expression is SimpleStringLiteral) { | |
223 library.path = expression.value; | |
224 } | |
225 } | |
226 } | |
227 } | |
228 _librariesMap.setLibrary(libraryName, library); | |
229 } | |
230 return null; | |
231 } | |
232 } | |
233 | |
234 /** | |
235 * Represents a single library in the SDK | |
236 */ | |
237 abstract class SdkLibrary { | |
238 /** | |
239 * Return the name of the category containing the library. | |
240 */ | |
241 String get category; | |
242 | |
243 /** | |
244 * Return `true` if this library can be compiled to JavaScript by dart2js. | |
245 */ | |
246 bool get isDart2JsLibrary; | |
247 | |
248 /** | |
249 * Return `true` if the library is documented. | |
250 */ | |
251 bool get isDocumented; | |
252 | |
253 /** | |
254 * Return `true` if the library is an implementation library. | |
255 */ | |
256 bool get isImplementation; | |
257 | |
258 /** | |
259 * Return `true` if library is internal can be used only by other SDK librarie
s. | |
260 */ | |
261 bool get isInternal; | |
262 | |
263 /** | |
264 * Return `true` if this library can be used for both client and server. | |
265 */ | |
266 bool get isShared; | |
267 | |
268 /** | |
269 * Return `true` if this library can be run on the VM. | |
270 */ | |
271 bool get isVmLibrary; | |
272 | |
273 /** | |
274 * Return the path to the file defining the library. The path is relative to | |
275 * the `lib` directory within the SDK. | |
276 */ | |
277 String get path; | |
278 | |
279 /** | |
280 * Return the short name of the library. This is the URI of the library, | |
281 * including `dart:`. | |
282 */ | |
283 String get shortName; | |
284 } | |
285 | |
286 /** | |
287 * The information known about a single library within the SDK. | |
288 */ | |
289 class SdkLibraryImpl implements SdkLibrary { | |
290 /** | |
291 * The bit mask used to access the bit representing the flag indicating | |
292 * whether a library is intended to work on the dart2js platform. | |
293 */ | |
294 static int DART2JS_PLATFORM = 1; | |
295 | |
296 /** | |
297 * The bit mask used to access the bit representing the flag indicating | |
298 * whether a library is intended to work on the VM platform. | |
299 */ | |
300 static int VM_PLATFORM = 2; | |
301 | |
302 /** | |
303 * The short name of the library. This is the name used after 'dart:' in a | |
304 * URI. | |
305 */ | |
306 String _shortName = null; | |
307 | |
308 /** | |
309 * The path to the file defining the library. The path is relative to the | |
310 * 'lib' directory within the SDK. | |
311 */ | |
312 String path = null; | |
313 | |
314 /** | |
315 * The name of the category containing the library. Unless otherwise specified | |
316 * in the libraries file all libraries are assumed to be shared between server | |
317 * and client. | |
318 */ | |
319 String category = "Shared"; | |
320 | |
321 /** | |
322 * A flag indicating whether the library is documented. | |
323 */ | |
324 bool _documented = true; | |
325 | |
326 /** | |
327 * A flag indicating whether the library is an implementation library. | |
328 */ | |
329 bool _implementation = false; | |
330 | |
331 /** | |
332 * An encoding of which platforms this library is intended to work on. | |
333 */ | |
334 int _platforms = 0; | |
335 | |
336 /** | |
337 * Initialize a newly created library to represent the library with the given | |
338 * [name]. | |
339 */ | |
340 SdkLibraryImpl(String name) { | |
341 this._shortName = name; | |
342 } | |
343 | |
344 /** | |
345 * Set whether the library is documented. | |
346 */ | |
347 void set documented(bool documented) { | |
348 this._documented = documented; | |
349 } | |
350 | |
351 /** | |
352 * Set whether the library is an implementation library. | |
353 */ | |
354 void set implementation(bool implementation) { | |
355 this._implementation = implementation; | |
356 } | |
357 | |
358 @override | |
359 bool get isDart2JsLibrary => (_platforms & DART2JS_PLATFORM) != 0; | |
360 | |
361 @override | |
362 bool get isDocumented => _documented; | |
363 | |
364 @override | |
365 bool get isImplementation => _implementation; | |
366 | |
367 @override | |
368 bool get isInternal => "Internal" == category; | |
369 | |
370 @override | |
371 bool get isShared => category == "Shared"; | |
372 | |
373 @override | |
374 bool get isVmLibrary => (_platforms & VM_PLATFORM) != 0; | |
375 | |
376 @override | |
377 String get shortName => _shortName; | |
378 | |
379 /** | |
380 * Record that this library can be compiled to JavaScript by dart2js. | |
381 */ | |
382 void setDart2JsLibrary() { | |
383 _platforms |= DART2JS_PLATFORM; | |
384 } | |
385 | |
386 /** | |
387 * Record that this library can be run on the VM. | |
388 */ | |
389 void setVmLibrary() { | |
390 _platforms |= VM_PLATFORM; | |
391 } | |
392 } | |
OLD | NEW |