Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 analyzer.src.generated.sdk; | 5 library analyzer.src.generated.sdk; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 String toString() { | 267 String toString() { |
| 268 StringBuffer buffer = new StringBuffer(); | 268 StringBuffer buffer = new StringBuffer(); |
| 269 bool needsSeparator = false; | 269 bool needsSeparator = false; |
| 270 void add(String optionName) { | 270 void add(String optionName) { |
| 271 if (needsSeparator) { | 271 if (needsSeparator) { |
| 272 buffer.write(', '); | 272 buffer.write(', '); |
| 273 } | 273 } |
| 274 buffer.write(optionName); | 274 buffer.write(optionName); |
| 275 needsSeparator = true; | 275 needsSeparator = true; |
| 276 } | 276 } |
| 277 | |
| 277 for (String path in paths) { | 278 for (String path in paths) { |
| 278 add(path); | 279 add(path); |
| 279 } | 280 } |
| 280 if (needsSeparator) { | 281 if (needsSeparator) { |
| 281 buffer.write(' '); | 282 buffer.write(' '); |
| 282 } | 283 } |
| 283 buffer.write('('); | 284 buffer.write('('); |
| 284 buffer.write(AnalysisOptionsImpl | 285 buffer.write(AnalysisOptionsImpl |
| 285 .decodeCrossContextOptions(options.encodeCrossContextOptions())); | 286 .decodeCrossContextOptions(options.encodeCrossContextOptions())); |
| 286 buffer.write(')'); | 287 buffer.write(')'); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 301 */ | 302 */ |
| 302 static String _IMPLEMENTATION = "implementation"; | 303 static String _IMPLEMENTATION = "implementation"; |
| 303 | 304 |
| 304 /** | 305 /** |
| 305 * The name of the optional parameter used to specify the path used when | 306 * The name of the optional parameter used to specify the path used when |
| 306 * compiling for dart2js. | 307 * compiling for dart2js. |
| 307 */ | 308 */ |
| 308 static String _DART2JS_PATH = "dart2jsPath"; | 309 static String _DART2JS_PATH = "dart2jsPath"; |
| 309 | 310 |
| 310 /** | 311 /** |
| 312 * The name of the `dart2js` platform. | |
| 313 */ | |
| 314 static String _DART2JS_PLATFORM = 'DART2JS_PLATFORM'; | |
| 315 | |
| 316 /** | |
| 311 * The name of the optional parameter used to indicate whether the library is | 317 * The name of the optional parameter used to indicate whether the library is |
| 312 * documented. | 318 * documented. |
| 313 */ | 319 */ |
| 314 static String _DOCUMENTED = "documented"; | 320 static String _DOCUMENTED = "documented"; |
| 315 | 321 |
| 316 /** | 322 /** |
| 317 * The name of the optional parameter used to specify the category of the | 323 * The name of the optional parameter used to specify the category of the |
| 318 * library. | 324 * library. |
| 319 */ | 325 */ |
| 320 static String _CATEGORIES = "categories"; | 326 static String _CATEGORIES = "categories"; |
| 321 | 327 |
| 322 /** | 328 /** |
| 329 * The name of the optional parameter used to specify the patches for | |
| 330 * the library. | |
| 331 */ | |
| 332 static String _PATCHES = "patches"; | |
| 333 | |
| 334 /** | |
| 323 * The name of the optional parameter used to specify the platforms on which | 335 * The name of the optional parameter used to specify the platforms on which |
| 324 * the library can be used. | 336 * the library can be used. |
| 325 */ | 337 */ |
| 326 static String _PLATFORMS = "platforms"; | 338 static String _PLATFORMS = "platforms"; |
| 327 | 339 |
| 328 /** | 340 /** |
| 329 * The value of the [PLATFORMS] parameter used to specify that the library can | 341 * The value of the [PLATFORMS] parameter used to specify that the library can |
| 330 * be used on the VM. | 342 * be used on the VM. |
| 331 */ | 343 */ |
| 332 static String _VM_PLATFORM = "VM_PLATFORM"; | 344 static String _VM_PLATFORM = "VM_PLATFORM"; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 } else if (argument is NamedExpression) { | 402 } else if (argument is NamedExpression) { |
| 391 String name = argument.name.label.name; | 403 String name = argument.name.label.name; |
| 392 Expression expression = argument.expression; | 404 Expression expression = argument.expression; |
| 393 if (name == _CATEGORIES) { | 405 if (name == _CATEGORIES) { |
| 394 library.category = | 406 library.category = |
| 395 convertCategories((expression as StringLiteral).stringValue); | 407 convertCategories((expression as StringLiteral).stringValue); |
| 396 } else if (name == _IMPLEMENTATION) { | 408 } else if (name == _IMPLEMENTATION) { |
| 397 library._implementation = (expression as BooleanLiteral).value; | 409 library._implementation = (expression as BooleanLiteral).value; |
| 398 } else if (name == _DOCUMENTED) { | 410 } else if (name == _DOCUMENTED) { |
| 399 library.documented = (expression as BooleanLiteral).value; | 411 library.documented = (expression as BooleanLiteral).value; |
| 412 } else if (name == _PATCHES) { | |
| 413 if (expression is MapLiteral) { | |
| 414 expression.entries.forEach((MapLiteralEntry entry) { | |
| 415 Expression key = entry.key; | |
| 416 Expression value = entry.value; | |
| 417 if (key is SimpleIdentifier && value is SimpleStringLiteral) { | |
|
Paul Berry
2016/10/10 19:14:38
Two issues:
1. The "patches" parameter should be
scheglov
2016/10/10 19:41:52
OK, I see now.
The key of this map must be a combi
| |
| 418 int platform = _convertPlatform(key.name); | |
| 419 library.addPatch(platform, value.value); | |
| 420 } | |
| 421 }); | |
| 422 } | |
| 400 } else if (name == _PLATFORMS) { | 423 } else if (name == _PLATFORMS) { |
| 401 if (expression is SimpleIdentifier) { | 424 if (expression is SimpleIdentifier) { |
| 402 String identifier = expression.name; | 425 String identifier = expression.name; |
| 403 if (identifier == _VM_PLATFORM) { | 426 if (identifier == _VM_PLATFORM) { |
| 404 library.setVmLibrary(); | 427 library.setVmLibrary(); |
| 405 } else { | 428 } else { |
| 406 library.setDart2JsLibrary(); | 429 library.setDart2JsLibrary(); |
| 407 } | 430 } |
| 408 } | 431 } |
| 409 } else if (_useDart2jsPaths && name == _DART2JS_PATH) { | 432 } else if (_useDart2jsPaths && name == _DART2JS_PATH) { |
| 410 if (expression is SimpleStringLiteral) { | 433 if (expression is SimpleStringLiteral) { |
| 411 library.path = expression.value; | 434 library.path = expression.value; |
| 412 } | 435 } |
| 413 } | 436 } |
| 414 } | 437 } |
| 415 } | 438 } |
| 416 _librariesMap.setLibrary(libraryName, library); | 439 _librariesMap.setLibrary(libraryName, library); |
| 417 } | 440 } |
| 418 return null; | 441 return null; |
| 419 } | 442 } |
| 443 | |
| 444 /** | |
| 445 * Return the platform constant value for the [name]. Throw [ArgumentError] | |
| 446 * if the given [name] is not a valid platform name. | |
| 447 */ | |
| 448 static int _convertPlatform(String name) { | |
| 449 if (name == _DART2JS_PLATFORM) { | |
| 450 return SdkLibraryImpl.DART2JS_PLATFORM; | |
| 451 } | |
| 452 if (name == _VM_PLATFORM) { | |
| 453 return SdkLibraryImpl.VM_PLATFORM; | |
| 454 } | |
| 455 throw new ArgumentError('Invalid platform name: $name'); | |
| 456 } | |
| 420 } | 457 } |
| 421 | 458 |
| 422 /** | 459 /** |
| 423 * Represents a single library in the SDK | 460 * Represents a single library in the SDK |
| 424 */ | 461 */ |
| 425 abstract class SdkLibrary { | 462 abstract class SdkLibrary { |
| 426 /** | 463 /** |
| 427 * Return the name of the category containing the library. | 464 * Return the name of the category containing the library. |
| 428 */ | 465 */ |
| 429 String get category; | 466 String get category; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 * Return the path to the file defining the library. The path is relative to | 499 * Return the path to the file defining the library. The path is relative to |
| 463 * the `lib` directory within the SDK. | 500 * the `lib` directory within the SDK. |
| 464 */ | 501 */ |
| 465 String get path; | 502 String get path; |
| 466 | 503 |
| 467 /** | 504 /** |
| 468 * Return the short name of the library. This is the URI of the library, | 505 * Return the short name of the library. This is the URI of the library, |
| 469 * including `dart:`. | 506 * including `dart:`. |
| 470 */ | 507 */ |
| 471 String get shortName; | 508 String get shortName; |
| 509 | |
| 510 /** | |
| 511 * Return the list of paths to the patch files that should be applied | |
| 512 * to this library for the given [platform], not `null`. | |
| 513 */ | |
| 514 List<String> getPatches(int platform); | |
| 472 } | 515 } |
| 473 | 516 |
| 474 /** | 517 /** |
| 475 * The information known about a single library within the SDK. | 518 * The information known about a single library within the SDK. |
| 476 */ | 519 */ |
| 477 class SdkLibraryImpl implements SdkLibrary { | 520 class SdkLibraryImpl implements SdkLibrary { |
| 478 /** | 521 /** |
| 479 * The bit mask used to access the bit representing the flag indicating | 522 * The bit mask used to access the bit representing the flag indicating |
| 480 * whether a library is intended to work on the dart2js platform. | 523 * whether a library is intended to work on the dart2js platform. |
| 481 */ | 524 */ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 * A flag indicating whether the library is an implementation library. | 557 * A flag indicating whether the library is an implementation library. |
| 515 */ | 558 */ |
| 516 bool _implementation = false; | 559 bool _implementation = false; |
| 517 | 560 |
| 518 /** | 561 /** |
| 519 * An encoding of which platforms this library is intended to work on. | 562 * An encoding of which platforms this library is intended to work on. |
| 520 */ | 563 */ |
| 521 int _platforms = 0; | 564 int _platforms = 0; |
| 522 | 565 |
| 523 /** | 566 /** |
| 567 * The mapping from the platform to the list of patches that should be | |
| 568 * applied for this library. | |
| 569 */ | |
| 570 final Map<int, List<String>> _patches = new HashMap<int, List<String>>(); | |
| 571 | |
| 572 /** | |
| 524 * Initialize a newly created library to represent the library with the given | 573 * Initialize a newly created library to represent the library with the given |
| 525 * [name]. | 574 * [name]. |
| 526 */ | 575 */ |
| 527 SdkLibraryImpl(this.shortName); | 576 SdkLibraryImpl(this.shortName); |
| 528 | 577 |
| 529 /** | 578 /** |
| 530 * Set whether the library is documented. | 579 * Set whether the library is documented. |
| 531 */ | 580 */ |
| 532 void set documented(bool documented) { | 581 void set documented(bool documented) { |
| 533 this._documented = documented; | 582 this._documented = documented; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 545 @override | 594 @override |
| 546 bool get isInternal => category == "Internal"; | 595 bool get isInternal => category == "Internal"; |
| 547 | 596 |
| 548 @override | 597 @override |
| 549 bool get isShared => category == "Shared"; | 598 bool get isShared => category == "Shared"; |
| 550 | 599 |
| 551 @override | 600 @override |
| 552 bool get isVmLibrary => (_platforms & VM_PLATFORM) != 0; | 601 bool get isVmLibrary => (_platforms & VM_PLATFORM) != 0; |
| 553 | 602 |
| 554 /** | 603 /** |
| 604 * Add a new patch with the given [path] that should be applied for the | |
| 605 * given [platform]. | |
| 606 */ | |
| 607 void addPatch(int platform, String path) { | |
| 608 assert(path != null); | |
| 609 _patches.putIfAbsent(platform, () => <String>[]).add(path); | |
| 610 } | |
| 611 | |
| 612 @override | |
| 613 List<String> getPatches(int platform) { | |
| 614 return _patches[platform] ?? const <String>[]; | |
| 615 } | |
| 616 | |
| 617 /** | |
| 555 * Record that this library can be compiled to JavaScript by dart2js. | 618 * Record that this library can be compiled to JavaScript by dart2js. |
| 556 */ | 619 */ |
| 557 void setDart2JsLibrary() { | 620 void setDart2JsLibrary() { |
| 558 _platforms |= DART2JS_PLATFORM; | 621 _platforms |= DART2JS_PLATFORM; |
| 559 } | 622 } |
| 560 | 623 |
| 561 /** | 624 /** |
| 562 * Record that this library can be run on the VM. | 625 * Record that this library can be run on the VM. |
| 563 */ | 626 */ |
| 564 void setVmLibrary() { | 627 void setVmLibrary() { |
| 565 _platforms |= VM_PLATFORM; | 628 _platforms |= VM_PLATFORM; |
| 566 } | 629 } |
| 567 } | 630 } |
| OLD | NEW |