Files
sdk/pkg/kernel/lib/target/implementation_option.dart
T
Alexander Markov 1d629221d1 Wrap the description of an option to fit within 80 columns
This is the follow-up for review comment

https://dart-review.googlesource.com/c/sdk/+/15644/2/pkg/kernel/lib/target/implementation_option.dart#10

to the CL 34df7f3599.

Change-Id: If0c17e36bbfb42df0aa410b04e5830ebd979d3cd
Reviewed-on: https://dart-review.googlesource.com/16301
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2017-10-25 17:27:49 +00:00

105 lines
3.0 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library kernel.target.implementation_options;
class VmOptions {
static final ImplementationOption strongAOT = new ImplementationOption._(
"strong-aot", Platform.vm, new DateTime.utc(2018, 1), """
Enables strong-mode whole-program optimizations for AOT (precompiler) mode of
the Dart VM.""");
}
final Map<String, ImplementationOption> implementationOptions =
ImplementationOption._validateOptions(<ImplementationOption>[
VmOptions.strongAOT,
]);
final RegExp _namePattern = new RegExp(r"^[-a-z0-9]+$");
class ImplementationOption {
final String name;
final String description;
final Platform platform;
final DateTime expires;
ImplementationOption._(
this.name, this.platform, this.expires, this.description);
bool _validate(int index, List<String> reasons) {
if (name == null) {
reasons.add("[name] is null for option #$index.");
return false;
}
if (!_namePattern.hasMatch(name)) {
reasons.add("'$name' doesn't match regular expression"
" '${_namePattern.pattern}'.");
return false;
}
if (description == null) {
reasons.add("[description] is null for option '$name'.");
return false;
}
if (description.isEmpty) {
reasons.add("[description] is empty for option '$name'.");
return false;
}
if (description == name) {
reasons.add("[description] == [name] for option '$name'.");
return false;
}
if (platform == null) {
reasons.add("[platform] is null for option '$name'.");
return false;
}
if (expires == null) {
reasons.add("[expires] is null for option '$name'.");
return false;
}
if (!expires.isUtc) {
reasons.add("[expires] isn't in UTC for option '$name'.");
return false;
}
if (expires.isBefore(new DateTime.now().toUtc())) {
print("Warning: option '$name' has expired "
"(see pkg/kernel/lib/target/implementation_option.dart).");
return false;
}
return true;
}
static Map<String, ImplementationOption> _validateOptions(
List<ImplementationOption> options) {
Map<String, ImplementationOption> result = <String, ImplementationOption>{};
int i = 0;
List<String> reasons = <String>[];
for (ImplementationOption option in options) {
if (result.containsKey(option.name)) {
throw "Duplicated option name at index $i.";
}
if (option._validate(i++, reasons)) {
result[option.name] = option;
}
}
if (reasons.isNotEmpty) {
throw reasons.join("\n");
}
return new Map<String, ImplementationOption>.unmodifiable(result);
}
static void validate(ImplementationOption option) {
List<String> reasons = <String>[];
if (!option._validate(-1, reasons)) {
throw new ArgumentError(reasons.join("\n"));
}
}
}
enum Platform {
analyzer,
dart2js,
devcompiler,
vm,
}