Chromium Code Reviews| Index: pkg/analyzer/lib/src/generated/sdk.dart |
| diff --git a/pkg/analyzer/lib/src/generated/sdk.dart b/pkg/analyzer/lib/src/generated/sdk.dart |
| index 7e86d8d965d7f70506c9bfe6da1045f51ab1f55b..7f78e556242df2ec082223024d5370b36ba3c203 100644 |
| --- a/pkg/analyzer/lib/src/generated/sdk.dart |
| +++ b/pkg/analyzer/lib/src/generated/sdk.dart |
| @@ -7,6 +7,7 @@ library analyzer.src.generated.sdk; |
| import 'dart:collection'; |
| import 'package:analyzer/dart/ast/ast.dart'; |
| +import 'package:analyzer/dart/ast/token.dart'; |
| import 'package:analyzer/dart/ast/visitor.dart'; |
| import 'package:analyzer/src/generated/engine.dart' |
| show AnalysisContext, AnalysisOptions, AnalysisOptionsImpl; |
| @@ -274,6 +275,7 @@ class SdkDescription { |
| buffer.write(optionName); |
| needsSeparator = true; |
| } |
| + |
| for (String path in paths) { |
| add(path); |
| } |
| @@ -308,6 +310,11 @@ class SdkLibrariesReader_LibraryBuilder extends RecursiveAstVisitor<Object> { |
| static String _DART2JS_PATH = "dart2jsPath"; |
| /** |
| + * The name of the `dart2js` platform. |
| + */ |
| + static String _DART2JS_PLATFORM = 'DART2JS_PLATFORM'; |
| + |
| + /** |
| * The name of the optional parameter used to indicate whether the library is |
| * documented. |
| */ |
| @@ -320,6 +327,12 @@ class SdkLibrariesReader_LibraryBuilder extends RecursiveAstVisitor<Object> { |
| static String _CATEGORIES = "categories"; |
| /** |
| + * The name of the optional parameter used to specify the patches for |
| + * the library. |
| + */ |
| + static String _PATCHES = "patches"; |
| + |
| + /** |
| * The name of the optional parameter used to specify the platforms on which |
| * the library can be used. |
| */ |
| @@ -397,6 +410,28 @@ class SdkLibrariesReader_LibraryBuilder extends RecursiveAstVisitor<Object> { |
| library._implementation = (expression as BooleanLiteral).value; |
| } else if (name == _DOCUMENTED) { |
| library.documented = (expression as BooleanLiteral).value; |
| + } else if (name == _PATCHES) { |
| + if (expression is MapLiteral) { |
| + expression.entries.forEach((MapLiteralEntry entry) { |
| + int platforms = _convertPlatforms(entry.key); |
| + Expression pathsListLiteral = entry.value; |
| + if (pathsListLiteral is ListLiteral) { |
| + List<String> paths = <String>[]; |
| + pathsListLiteral.elements.forEach((Expression pathExpr) { |
| + if (pathExpr is SimpleStringLiteral) { |
| + paths.add(pathExpr.value); |
| + } else { |
| + throw new ArgumentError( |
| + 'The "patch" argument items must be simple strings.'); |
| + } |
| + }); |
| + library.setPatchPaths(platforms, paths); |
| + } else { |
| + throw new ArgumentError( |
| + 'The "patch" argument values must be list literals.'); |
| + } |
| + }); |
| + } |
| } else if (name == _PLATFORMS) { |
| if (expression is SimpleIdentifier) { |
| String identifier = expression.name; |
| @@ -417,6 +452,43 @@ class SdkLibrariesReader_LibraryBuilder extends RecursiveAstVisitor<Object> { |
| } |
| return null; |
| } |
| + |
| + /** |
| + * Return the platform constant value for the given [expr]. |
| + * Throw [ArgumentError] if not a valid platform name given. |
| + */ |
| + static int _convertPlatform(Expression expr) { |
| + if (expr is SimpleIdentifier) { |
| + String name = expr.name; |
| + if (name == _DART2JS_PLATFORM) { |
| + return SdkLibraryImpl.DART2JS_PLATFORM; |
| + } |
| + if (name == _VM_PLATFORM) { |
| + return SdkLibraryImpl.VM_PLATFORM; |
| + } |
| + throw new ArgumentError('Invalid platform name: $name'); |
| + } |
| + throw new ArgumentError('Invalid platform type: ${expr.runtimeType}'); |
| + } |
| + |
| + /** |
| + * Return the platforms combination value for the [expr], which should be |
| + * either `name1 | name2` or `name`. Throw [ArgumentError] if any of the |
| + * names is not a valid platform name. |
| + */ |
| + static int _convertPlatforms(Expression expr) { |
| + if (expr is BinaryExpression) { |
| + TokenType operator = expr.operator?.type; |
| + if (operator == TokenType.BAR) { |
| + return _convertPlatforms(expr.leftOperand) | |
| + _convertPlatforms(expr.rightOperand); |
| + } else { |
| + throw new ArgumentError('Invalid platforms combination: $operator'); |
| + } |
| + } else { |
| + return _convertPlatform(expr); |
| + } |
| + } |
| } |
| /** |
| @@ -469,6 +541,12 @@ abstract class SdkLibrary { |
| * including `dart:`. |
| */ |
| String get shortName; |
| + |
| + /** |
| + * Return the list of paths to the patch files that should be applied |
| + * to this library for the given [platform], not `null`. |
| + */ |
| + List<String> getPatches(int platform); |
|
Bill Hesse
2016/10/11 21:35:59
This is a breaking change to the interface. You n
|
| } |
| /** |
| @@ -521,6 +599,14 @@ class SdkLibraryImpl implements SdkLibrary { |
| int _platforms = 0; |
| /** |
| + * The mapping from the platform combination to the list of paths (relative |
| + * to the `sdk/lib` folder) of patches that should be applied to this library |
| + * on every platform in the combination. |
| + */ |
| + final Map<int, List<String>> _platformsToPatchPaths = |
| + new HashMap<int, List<String>>(); |
| + |
| + /** |
| * Initialize a newly created library to represent the library with the given |
| * [name]. |
| */ |
| @@ -551,6 +637,17 @@ class SdkLibraryImpl implements SdkLibrary { |
| @override |
| bool get isVmLibrary => (_platforms & VM_PLATFORM) != 0; |
| + @override |
| + List<String> getPatches(int platform) { |
| + List<String> paths = <String>[]; |
| + _platformsToPatchPaths.forEach((int platforms, List<String> value) { |
| + if ((platforms & platform) != 0) { |
| + paths.addAll(value); |
| + } |
| + }); |
| + return paths; |
| + } |
| + |
| /** |
| * Record that this library can be compiled to JavaScript by dart2js. |
| */ |
| @@ -559,6 +656,14 @@ class SdkLibraryImpl implements SdkLibrary { |
| } |
| /** |
| + * Add a new patch with the given [path] that should be applied for the |
| + * given [platforms]. |
| + */ |
| + void setPatchPaths(int platforms, List<String> paths) { |
| + _platformsToPatchPaths[platforms] = paths; |
| + } |
| + |
| + /** |
| * Record that this library can be run on the VM. |
| */ |
| void setVmLibrary() { |