Skip to content

Commit 5cc9455

Browse files
sigmundchcommit-bot@chromium.org
authored andcommitted
scanner-tool: add explicit command-line arguments to enable printing tokens
This will be used instead of -DprintTokens=true. Context: we use this tool in bazel where we use a modular pipeline. That pipeline will no longer support dart environment variables due to #36513. In this specific file the intent was anyways to pass an option when launching the program, so a command-line option is appropriate IMO. Change-Id: I5187190a01afe59aef57ec6a7311b1e380313a81 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99102 Reviewed-by: Ari Aye <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Sigmund Cherem <[email protected]>
1 parent 9e279a5 commit 5cc9455

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

pkg/front_end/lib/src/fasta/scanner/scanner_main.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,18 @@ import 'io.dart' show readBytesFromFileSync;
88

99
import '../scanner.dart' show ErrorToken, Token, scan;
1010

11-
scanAll(Map<Uri, List<int>> files) {
11+
scanAll(Map<Uri, List<int>> files, {bool verbose: false, bool verify: false}) {
1212
Stopwatch sw = new Stopwatch()..start();
1313
int byteCount = 0;
1414
files.forEach((Uri uri, List<int> bytes) {
1515
var token = scan(bytes).tokens;
16-
if (const bool.fromEnvironment("printTokens")) {
17-
printTokens(token);
18-
}
19-
if (const bool.fromEnvironment('verifyErrorTokens')) {
20-
verifyErrorTokens(token, uri);
21-
}
16+
if (verbose) printTokens(token);
17+
if (verify) verifyErrorTokens(token, uri);
2218
byteCount += bytes.length - 1;
2319
});
2420
sw.stop();
2521
print("Scanning files took: ${sw.elapsed}");
26-
print("Bytes/ms: ${byteCount/sw.elapsedMilliseconds}");
22+
print("Bytes/ms: ${byteCount / sw.elapsedMilliseconds}");
2723
}
2824

2925
void printTokens(Token token) {
@@ -78,12 +74,25 @@ void verifyErrorTokens(Token firstToken, Uri uri) {
7874
mainEntryPoint(List<String> arguments) {
7975
Map<Uri, List<int>> files = <Uri, List<int>>{};
8076
Stopwatch sw = new Stopwatch()..start();
81-
for (String name in arguments) {
82-
Uri uri = Uri.base.resolve(name);
77+
bool verbose = const bool.fromEnvironment("printTokens");
78+
bool verify = const bool.fromEnvironment('verifyErrorTokens');
79+
for (String arg in arguments) {
80+
if (arg.startsWith('--')) {
81+
if (arg == '--print-tokens') {
82+
verbose = true;
83+
} else if (arg == '--verify-error-tokens') {
84+
verify = true;
85+
} else {
86+
print('Unrecognized option: $arg');
87+
}
88+
continue;
89+
}
90+
91+
Uri uri = Uri.base.resolve(arg);
8392
List<int> bytes = readBytesFromFileSync(uri);
8493
files[uri] = bytes;
8594
}
8695
sw.stop();
8796
print("Reading files took: ${sw.elapsed}");
88-
scanAll(files);
97+
scanAll(files, verbose: verbose, verify: verify);
8998
}

0 commit comments

Comments
 (0)