[cfe] Migrate tool/_fasta libraries - that don't depend on entrypoint.dart or package:testing Change-Id: I007c67c611aa99f35851d2423834ee440f3b224b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207137 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
diff --git a/pkg/front_end/tool/_fasta/abcompile.dart b/pkg/front_end/tool/_fasta/abcompile.dart index 26f815a..a9e3125 100644 --- a/pkg/front_end/tool/_fasta/abcompile.dart +++ b/pkg/front_end/tool/_fasta/abcompile.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:async'; import 'dart:convert'; import 'dart:math'; @@ -11,7 +9,7 @@ import 'standard_deviation.dart'; -const String bRootPath = +const String? bRootPath = bool.hasEnvironment("bRoot") ? String.fromEnvironment("bRoot") : null; const int abIterations = int.fromEnvironment("abIterations", defaultValue: 15); const int iterations = int.fromEnvironment("iterations", defaultValue: 15); @@ -31,7 +29,7 @@ Uri aRoot = Platform.script.resolve('../../../..'); // The root of the other Dart SDK repo "B" - Uri bRoot = new Uri.directory(bRootPath); + Uri bRoot = new Uri.directory(bRootPath!); // Sanity check String relPath = 'pkg/front_end/tool/_fasta/compile.dart'; @@ -183,15 +181,15 @@ workingDirectory: workingDirPath); // ignore: unawaited_futures stderr.addStream(process.stderr); - StreamSubscription<String> stdOutSubscription; + StreamSubscription<String>? stdOutSubscription; stdOutSubscription = process.stdout .transform(utf8.decoder) .transform(new LineSplitter()) .listen(processLine, onDone: () { - stdOutSubscription.cancel(); + stdOutSubscription!.cancel(); }, onError: (e) { print('Error: $e'); - stdOutSubscription.cancel(); + stdOutSubscription!.cancel(); }); int code = await process.exitCode; if (code != 0) {
diff --git a/pkg/front_end/tool/_fasta/bench_maker.dart b/pkg/front_end/tool/_fasta/bench_maker.dart index 22732a7..4e95837 100644 --- a/pkg/front_end/tool/_fasta/bench_maker.dart +++ b/pkg/front_end/tool/_fasta/bench_maker.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - library fasta.tool.entry_points; import "dart:convert" show JsonEncoder; @@ -49,8 +47,10 @@ final List<TypeParameter> usedTypeParameters = <TypeParameter>[]; String serializeTypeChecks(List<Object> typeChecks) { - for (List<Object> list in typeChecks) { - writeTypeCheck(list[0], list[1], list[2]); + for (Object list in typeChecks) { + List<Object> typeCheck = list as List<Object>; + writeTypeCheck(typeCheck[0] as DartType, typeCheck[1] as DartType, + typeCheck[2] as bool); } writeClasses(); return jsonEncode(this); @@ -133,11 +133,11 @@ } } - void writeClass(Class cls, Set<Class> writtenClasses) { + void writeClass(Class? cls, Set<Class> writtenClasses) { if (cls == null || !writtenClasses.add(cls)) return; - Supertype supertype = cls.supertype; + Supertype? supertype = cls.supertype; writeClass(supertype?.classNode, writtenClasses); - Supertype mixedInType = cls.mixedInType; + Supertype? mixedInType = cls.mixedInType; writeClass(mixedInType?.classNode, writtenClasses); for (Supertype implementedType in cls.implementedTypes) { writeClass(implementedType.classNode, writtenClasses); @@ -164,7 +164,7 @@ implementedType.asInterfaceType.accept1(this, sb); first = false; } - Procedure callOperator; + Procedure? callOperator; for (Procedure procedure in cls.procedures) { if (procedure.name.text == "call") { callOperator = procedure; @@ -183,11 +183,11 @@ } String computeName(TreeNode node) { - String name = nodeNames[node]; + String? name = nodeNames[node]; if (name != null) return name; if (node is Class) { Library library = node.enclosingLibrary; - String uriString = "${library?.importUri}"; + String uriString = "${library.importUri}"; if (uriString == "dart:core" || uriString == "dart:async") { if (!usedNames.add(node.name)) { throw "Class name conflict for $node"; @@ -336,7 +336,7 @@ sb.write(name); if (node.promotedBound != null) { sb.write(" & "); - node.promotedBound.accept1(this, sb); + node.promotedBound!.accept1(this, sb); } }
diff --git a/pkg/front_end/tool/_fasta/command_line.dart b/pkg/front_end/tool/_fasta/command_line.dart index d4b5b05..6ab0e47 100644 --- a/pkg/front_end/tool/_fasta/command_line.dart +++ b/pkg/front_end/tool/_fasta/command_line.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - library fasta.tool.command_line; import 'dart:io' show exit; @@ -110,7 +108,7 @@ /// All other options require an option value, either on the form `--option /// value` or `--option=value`. static ParsedArguments parse( - List<String> arguments, Map<String, ValueSpecification> specification) { + List<String> arguments, Map<String, ValueSpecification>? specification) { specification ??= const <String, ValueSpecification>{}; ParsedArguments result = new ParsedArguments(); int index = arguments.indexOf("--"); @@ -123,7 +121,7 @@ while (iterator.moveNext()) { String argument = iterator.current; if (argument.startsWith("-") || argument == "/?" || argument == "/h") { - String value; + String? value; if (argument.startsWith("-D")) { value = argument.substring("-D".length); argument = "-D"; @@ -134,14 +132,14 @@ argument = argument.substring(0, index); } } - ValueSpecification valueSpecification = specification[argument]; + ValueSpecification? valueSpecification = specification[argument]; if (valueSpecification == null) { throw new CommandLineProblem.deprecated( "Unknown option '$argument'."); } String canonicalArgument = argument; if (valueSpecification.alias != null) { - canonicalArgument = valueSpecification.alias; + canonicalArgument = valueSpecification.alias as String; valueSpecification = specification[valueSpecification.alias]; } if (valueSpecification == null) { @@ -268,7 +266,7 @@ enableNullSafety: isExperimentEnabled(ExperimentalFlag.nonNullable, explicitExperimentalFlags: explicitExperimentalFlags)); - final Target target = getTarget(targetName, flags); + final Target? target = getTarget(targetName, flags); if (target == null) { return throw new CommandLineProblem.deprecated( "Target '${targetName}' not recognized. " @@ -302,7 +300,7 @@ final bool compileSdk = options.containsKey(Flags.compileSdk); - final String singleRootScheme = options[Flags.singleRootScheme]; + final String? singleRootScheme = options[Flags.singleRootScheme]; final Uri singleRootBase = options[Flags.singleRootBase]; final bool nnbdStrongMode = options[Flags.nnbdStrongMode]; @@ -418,7 +416,7 @@ throwCommandLineProblem( "Target '${target.name}' requires an explicit " "'${Flags.platform}' option."); - }))); + })!)); compilerOptions ..sdkRoot = sdk ..sdkSummary = platform @@ -439,9 +437,9 @@ List<String> arguments, bool areRestArgumentsInputs, Future<T> f(CompilerContext context, List<String> restArguments)) { - ParsedArguments parsedArguments; + ParsedArguments? parsedArguments; ProcessedOptions options; - CommandLineProblem problem; + CommandLineProblem? problem; try { parsedArguments = ParsedArguments.parse(arguments, optionSpecification); options = analyzeCommandLine( @@ -466,13 +464,13 @@ exit(1); } - return f(c, parsedArguments.arguments); + return f(c, parsedArguments!.arguments); }, errorOnMissingInput: problem == null); } Message computeUsage(String programName, bool verbose) { String basicUsage = "Usage: $programName [options] dartfile\n"; - String summary; + String? summary; String options = (verbose ? messageFastaUsageLong.message : messageFastaUsageShort.message) .trim(); @@ -508,7 +506,7 @@ } Future<T> runProtectedFromAbort<T>(Future<T> Function() action, - [T failingValue]) async { + [T? failingValue]) async { if (CompilerContext.isActive) { throw "runProtectedFromAbort should be called from 'main'," " that is, outside a compiler context."; @@ -527,14 +525,14 @@ abstract class ValueSpecification { const ValueSpecification(); - String get alias => null; + String? get alias => null; dynamic get defaultValue => null; bool get requiresValue => true; void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value); + String argument, String? value); } class AliasValue extends ValueSpecification { @@ -546,7 +544,7 @@ throw new UnsupportedError("AliasValue.requiresValue"); void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { + String argument, String? value) { throw new UnsupportedError("AliasValue.processValue"); } } @@ -555,7 +553,7 @@ const UriValue(); void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { + String argument, String? value) { if (result.options.containsKey(canonicalArgument)) { throw new CommandLineProblem.deprecated( "Multiple values for '$argument': " @@ -563,7 +561,7 @@ } // TODO(ahe): resolve Uris lazily, so that schemes provided by // other flags can be used for parsed command-line arguments too. - result.options[canonicalArgument] = resolveInputUri(value); + result.options[canonicalArgument] = resolveInputUri(value!); } } @@ -571,13 +569,13 @@ const StringValue(); void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { + String argument, String? value) { if (result.options.containsKey(canonicalArgument)) { throw new CommandLineProblem.deprecated( "Multiple values for '$argument': " "'${result.options[canonicalArgument]}' and '$value'."); } - result.options[canonicalArgument] = value; + result.options[canonicalArgument] = value!; } } @@ -589,7 +587,7 @@ bool get requiresValue => false; void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { + String argument, String? value) { if (result.options.containsKey(canonicalArgument)) { throw new CommandLineProblem.deprecated( "Multiple values for '$argument': " @@ -613,13 +611,13 @@ const IntValue(); void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { + String argument, String? value) { if (result.options.containsKey(canonicalArgument)) { throw new CommandLineProblem.deprecated( "Multiple values for '$argument': " "'${result.options[canonicalArgument]}' and '$value'."); } - int parsedValue = int.tryParse(value); + int? parsedValue = int.tryParse(value!); if (parsedValue == null) { throw new CommandLineProblem.deprecated( "Value for '$argument', '$value', isn't an int."); @@ -632,8 +630,8 @@ const DefineValue(); void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { - int index = value.indexOf('='); + String argument, String? value) { + int index = value!.indexOf('='); String name; String expression; if (index != -1) { @@ -651,10 +649,10 @@ const StringListValue(); void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { + String argument, String? value) { result.options .putIfAbsent(canonicalArgument, () => <String>[]) - .addAll(value.split(",")); + .addAll(value!.split(",")); } } @@ -662,9 +660,9 @@ const UriListValue(); void processValue(ParsedArguments result, String canonicalArgument, - String argument, String value) { + String argument, String? value) { result.options .putIfAbsent(canonicalArgument, () => <Uri>[]) - .addAll(value.split(",").map(resolveInputUri)); + .addAll(value!.split(",").map(resolveInputUri)); } }
diff --git a/pkg/front_end/tool/_fasta/compile_platform_legacy_test.dart b/pkg/front_end/tool/_fasta/compile_platform_legacy_test.dart index 1f624d3..985026c 100644 --- a/pkg/front_end/tool/_fasta/compile_platform_legacy_test.dart +++ b/pkg/front_end/tool/_fasta/compile_platform_legacy_test.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE.md file. -// @dart=2.9 - library fasta.test.compile_platform_test; import 'dart:io';
diff --git a/pkg/front_end/tool/_fasta/compile_platform_test.dart b/pkg/front_end/tool/_fasta/compile_platform_test.dart index 1f624d3..985026c 100644 --- a/pkg/front_end/tool/_fasta/compile_platform_test.dart +++ b/pkg/front_end/tool/_fasta/compile_platform_test.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE.md file. -// @dart=2.9 - library fasta.test.compile_platform_test; import 'dart:io';
diff --git a/pkg/front_end/tool/_fasta/generate_experimental_flags.dart b/pkg/front_end/tool/_fasta/generate_experimental_flags.dart index f52aee6..a452b9f 100644 --- a/pkg/front_end/tool/_fasta/generate_experimental_flags.dart +++ b/pkg/front_end/tool/_fasta/generate_experimental_flags.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:io' show File; import 'package:_fe_analyzer_shared/src/scanner/characters.dart' @@ -50,7 +48,7 @@ int currentVersionMajor; int currentVersionMinor; { - String currentVersion = getAsVersionNumberString(yaml['current-version']); + String currentVersion = getAsVersionNumberString(yaml['current-version'])!; List<String> split = currentVersion.split("."); currentVersionMajor = int.parse(split[0]); currentVersionMinor = int.parse(split[1]); @@ -84,7 +82,7 @@ int currentVersionMajor; int currentVersionMinor; { - String currentVersion = getAsVersionNumberString(yaml['current-version']); + String currentVersion = getAsVersionNumberString(yaml['current-version'])!; List<String> split = currentVersion.split("."); currentVersionMajor = int.parse(split[0]); currentVersionMinor = int.parse(split[1]); @@ -135,7 +133,7 @@ for (String key in keys) { int major; int minor; - String enabledIn = + String? enabledIn = getAsVersionNumberString((features[key] as YamlMap)['enabledIn']); if (enabledIn == null) { major = currentVersionMajor; @@ -192,7 +190,7 @@ for (String key in keys) { int major; int minor; - String enabledIn = + String? enabledIn = getAsVersionNumberString((features[key] as YamlMap)['enabledIn']); if (enabledIn != null) { List<String> split = enabledIn.split("."); @@ -213,9 +211,9 @@ for (String key in keys) { int major; int minor; - String enabledIn = + String? enabledIn = getAsVersionNumberString((features[key] as YamlMap)['enabledIn']); - String experimentalReleaseVersion = getAsVersionNumberString( + String? experimentalReleaseVersion = getAsVersionNumberString( (features[key] as YamlMap)['experimentalReleaseVersion']); if (experimentalReleaseVersion != null) { List<String> split = experimentalReleaseVersion.split("."); @@ -296,7 +294,7 @@ return identifier.toString(); } -String getAsVersionNumberString(dynamic value) { +String? getAsVersionNumberString(dynamic value) { if (value == null) return null; if (value is String) return value; if (value is double) return "$value";
diff --git a/pkg/front_end/tool/_fasta/generate_messages.dart b/pkg/front_end/tool/_fasta/generate_messages.dart index 8ddafe5..3a971c3 100644 --- a/pkg/front_end/tool/_fasta/generate_messages.dart +++ b/pkg/front_end/tool/_fasta/generate_messages.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:io' show File, exitCode; import "package:_fe_analyzer_shared/src/messages/severity.dart" @@ -96,7 +94,7 @@ while (description is String) { description = yaml[description]; } - Map<dynamic, dynamic> map = description; + Map<dynamic, dynamic>? map = description; if (map == null) { throw "No 'template:' in key $name."; } @@ -109,7 +107,7 @@ index = -1; // Continue looking for other problems. } else { - String otherName = indexNameMap[index]; + String? otherName = indexNameMap[index]; if (otherName != null) { print('Error: The "index:" field must be unique, ' 'but is the same for $otherName and $name'); @@ -166,8 +164,8 @@ Template(this.text, {this.isShared}) : assert(isShared != null); } -Template compileTemplate(String name, int index, String template, String tip, - Object analyzerCode, String severity) { +Template compileTemplate(String name, int? index, String? template, String? tip, + Object? analyzerCode, String? severity) { if (template == null) { print('Error: missing template for message: $name'); exitCode = 1; @@ -194,9 +192,9 @@ for (Match match in placeholderPattern.allMatches("$template\n${tip ?? ''}")) { - String name = match[1]; - String padding = match[2]; - String fractionDigits = match[3]; + String name = match[1]!; + String? padding = match[2]; + String? fractionDigits = match[3]; String format(String name) { String conversion; @@ -205,7 +203,7 @@ } else { conversion = "$name.toStringAsFixed($fractionDigits)"; } - if (padding.isNotEmpty) { + if (padding!.isNotEmpty) { if (padding.startsWith("0")) { conversion += ".padLeft(${int.parse(padding)}, '0')"; } else { @@ -416,13 +414,13 @@ if (analyzerCode is String) { analyzerCode = <String>[analyzerCode]; } - List<Object> codes = analyzerCode; + List<Object> codes = analyzerCode as List<Object>; // If "index:" is defined, then "analyzerCode:" should not be generated // in the front end. See comment in messages.yaml codeArguments.add('analyzerCodes: <String>["${codes.join('", "')}"]'); } if (severity != null) { - String severityEnumName = severityEnumNames[severity]; + String? severityEnumName = severityEnumNames[severity]; if (severityEnumName == null) { throw "Unknown severity '$severity'"; } @@ -430,6 +428,7 @@ } if (parameters.isEmpty && conversions.isEmpty && arguments.isEmpty) { + // ignore: unnecessary_null_comparison if (template != null) { codeArguments.add('message: r"""$template"""'); } @@ -448,6 +447,7 @@ } List<String> templateArguments = <String>[]; + // ignore: unnecessary_null_comparison if (template != null) { templateArguments.add('messageTemplate: r"""$template"""'); }
diff --git a/pkg/front_end/tool/_fasta/log_collector.dart b/pkg/front_end/tool/_fasta/log_collector.dart index 95dc56f..01fac75 100644 --- a/pkg/front_end/tool/_fasta/log_collector.dart +++ b/pkg/front_end/tool/_fasta/log_collector.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:convert' show jsonDecode, utf8; import 'dart:isolate' show RawReceivePort; @@ -55,7 +53,7 @@ String month = "${time.month}".padLeft(2, "0"); String day = "${time.day}".padLeft(2, "0"); String us = "${time.microsecondsSinceEpoch}".padLeft(19, '0'); - Uri uri = Uri.base + Uri? uri = Uri.base .resolve("crash_logs/${data['client']}/$year-$month-$day/$us.log"); File file = new File.fromUri(uri); await file.parent.create(recursive: true); @@ -63,12 +61,12 @@ print("Wrote ${uri.toFilePath()}"); String type = data["type"]; - String text = data["uri"]; + String? text = data["uri"]; uri = text == null ? null : Uri.parse(text); int charOffset = data["offset"]; var error = data["error"]; text = data["trace"]; - StackTrace trace = text == null ? null : new StackTrace.fromString(text); + StackTrace? trace = text == null ? null : new StackTrace.fromString(text); String client = data["client"]; print(""" date: ${time}