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