Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: lib/src/options.dart

Issue 957013002: Typecheck map and list literals (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: Add flag to reject casts in const contexts Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /// Set of flags and options passed to the compiler 5 /// Set of flags and options passed to the compiler
6 library ddc.src.options; 6 library ddc.src.options;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', 56 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/',
57 this.packagePaths: const [], this.inferFromOverrides: true, 57 this.packagePaths: const [], this.inferFromOverrides: true,
58 this.inferStaticsFromIdentifiers: false, 58 this.inferStaticsFromIdentifiers: false,
59 this.inferInNonStableOrder: false, 59 this.inferInNonStableOrder: false,
60 this.onlyInferConstsAndFinalFields: false}); 60 this.onlyInferConstsAndFinalFields: false});
61 } 61 }
62 62
63 // TODO(vsm): Merge RulesOptions and TypeOptions 63 // TODO(vsm): Merge RulesOptions and TypeOptions
64 /// Options used by ddc's RestrictedRules. 64 /// Options used by ddc's RestrictedRules.
65 class RulesOptions extends TypeOptions { 65 class RulesOptions extends TypeOptions {
66 /// Whether to allow casts in constant contexts.
67 final bool allowConstCasts;
68
66 /// Whether to use covariant generics 69 /// Whether to use covariant generics
67 final bool covariantGenerics; 70 final bool covariantGenerics;
68 71
69 /// Whether to inject casts between Dart assignable types. 72 /// Whether to inject casts between Dart assignable types.
70 final bool relaxedCasts; 73 final bool relaxedCasts;
71 74
72 /// Whether to use static types for code generation. 75 /// Whether to use static types for code generation.
73 final bool ignoreTypes; 76 final bool ignoreTypes;
74 77
75 RulesOptions({this.covariantGenerics: true, this.relaxedCasts: true, 78 RulesOptions({this.allowConstCasts: true, this.covariantGenerics: true,
76 this.ignoreTypes: false}); 79 this.relaxedCasts: true, this.ignoreTypes: false});
77 } 80 }
78 81
79 /// General options used by the dev compiler. 82 /// General options used by the dev compiler.
80 class CompilerOptions implements RulesOptions, ResolverOptions { 83 class CompilerOptions implements RulesOptions, ResolverOptions {
81 /// Whether to check the sdk libraries. 84 /// Whether to check the sdk libraries.
82 final bool checkSdk; 85 final bool checkSdk;
83 86
84 /// Whether to dump summary information on the console. 87 /// Whether to dump summary information on the console.
85 final bool dumpInfo; 88 final bool dumpInfo;
86 89
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't 123 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't
121 /// be determined 124 /// be determined
122 final String dartSdkPath; 125 final String dartSdkPath;
123 126
124 /// Minimum log-level reported on the command-line. 127 /// Minimum log-level reported on the command-line.
125 final Level logLevel; 128 final Level logLevel;
126 129
127 /// File where to start compilation from. 130 /// File where to start compilation from.
128 final String entryPointFile; 131 final String entryPointFile;
129 132
133 /// Whether to allow casts in constant contexts.
134 @override
135 final bool allowConstCasts;
136
130 /// Whether to use covariant generics 137 /// Whether to use covariant generics
131 @override 138 @override
132 final bool covariantGenerics; 139 final bool covariantGenerics;
133 140
134 /// Whether to inject casts between Dart assignable types. 141 /// Whether to inject casts between Dart assignable types.
135 @override 142 @override
136 final bool relaxedCasts; 143 final bool relaxedCasts;
137 144
138 /// Whether to resolve 'package:' uris using the multi-package resolver. 145 /// Whether to resolve 'package:' uris using the multi-package resolver.
139 @override 146 @override
(...skipping 26 matching lines...) Expand all
166 final bool onlyInferConstsAndFinalFields; 173 final bool onlyInferConstsAndFinalFields;
167 174
168 /// List of non-nullable types. 175 /// List of non-nullable types.
169 @override 176 @override
170 final List<String> nonnullableTypes; 177 final List<String> nonnullableTypes;
171 178
172 /// Whether to use static types for code generation. 179 /// Whether to use static types for code generation.
173 @override 180 @override
174 final bool ignoreTypes; 181 final bool ignoreTypes;
175 182
176 CompilerOptions({this.checkSdk: false, this.dumpInfo: false, 183 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false,
177 this.dumpInfoFile, this.dumpSrcDir, this.forceCompile: false, 184 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir,
178 this.formatOutput: false, this.cheapTestFormat: false, 185 this.forceCompile: false, this.formatOutput: false,
179 this.ignoreTypes: false, this.outputDir, this.outputDart: false, 186 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir,
180 this.useColors: true, this.covariantGenerics: true, 187 this.outputDart: false, this.useColors: true,
181 this.relaxedCasts: true, this.useMultiPackage: false, 188 this.covariantGenerics: true, this.relaxedCasts: true,
182 this.packageRoot: 'packages/', this.packagePaths: const [], 189 this.useMultiPackage: false, this.packageRoot: 'packages/',
183 this.inferFromOverrides: true, this.inferStaticsFromIdentifiers: false, 190 this.packagePaths: const [], this.inferFromOverrides: true,
191 this.inferStaticsFromIdentifiers: false,
184 this.inferInNonStableOrder: false, 192 this.inferInNonStableOrder: false,
185 this.onlyInferConstsAndFinalFields: false, 193 this.onlyInferConstsAndFinalFields: false,
186 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, 194 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false,
187 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, 195 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE,
188 this.entryPointFile: null}); 196 this.entryPointFile: null});
189 } 197 }
190 198
191 /// Parses options from the command-line 199 /// Parses options from the command-line
192 CompilerOptions parseOptions(List<String> argv) { 200 CompilerOptions parseOptions(List<String> argv) {
193 ArgResults args = argParser.parse(argv); 201 ArgResults args = argParser.parse(argv);
194 var levelName = args['log'].toUpperCase(); 202 var levelName = args['log'].toUpperCase();
195 var useColors = stdioType(stdout) == StdioType.TERMINAL; 203 var useColors = stdioType(stdout) == StdioType.TERMINAL;
196 var sdkPath = args['dart-sdk']; 204 var sdkPath = args['dart-sdk'];
197 if (sdkPath == null && !args['mock-sdk']) { 205 if (sdkPath == null && !args['mock-sdk']) {
198 sdkPath = getSdkDir(argv).path; 206 sdkPath = getSdkDir(argv).path;
199 } 207 }
200 return new CompilerOptions( 208 return new CompilerOptions(
209 allowConstCasts: args['allow-const-casts'],
201 checkSdk: args['sdk-check'], 210 checkSdk: args['sdk-check'],
202 dumpInfo: args['dump-info'], 211 dumpInfo: args['dump-info'],
203 dumpInfoFile: args['dump-info-file'], 212 dumpInfoFile: args['dump-info-file'],
204 dumpSrcDir: args['dump-src-to'], 213 dumpSrcDir: args['dump-src-to'],
205 forceCompile: args['force-compile'], 214 forceCompile: args['force-compile'],
206 formatOutput: args['dart-gen-fmt'], 215 formatOutput: args['dart-gen-fmt'],
207 ignoreTypes: args['ignore-types'], 216 ignoreTypes: args['ignore-types'],
208 outputDart: args['dart-gen'], 217 outputDart: args['dart-gen'],
209 outputDir: args['out'], 218 outputDir: args['out'],
210 covariantGenerics: args['covariant-generics'], 219 covariantGenerics: args['covariant-generics'],
(...skipping 11 matching lines...) Expand all
222 help: args['help'], 231 help: args['help'],
223 useMockSdk: args['mock-sdk'], 232 useMockSdk: args['mock-sdk'],
224 dartSdkPath: sdkPath, 233 dartSdkPath: sdkPath,
225 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName, 234 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName,
226 orElse: () => Level.SEVERE), 235 orElse: () => Level.SEVERE),
227 entryPointFile: args.rest.length == 0 ? null : args.rest.first); 236 entryPointFile: args.rest.length == 0 ? null : args.rest.first);
228 } 237 }
229 238
230 final ArgParser argParser = new ArgParser() 239 final ArgParser argParser = new ArgParser()
231 // resolver/checker options 240 // resolver/checker options
232 ..addFlag( 241 ..addFlag('allow-const-casts',
233 'sdk-check', abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) 242 help: 'Allow casts in const contexts', defaultsTo: true)
243 ..addFlag('sdk-check',
244 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false)
234 ..addFlag('mock-sdk', 245 ..addFlag('mock-sdk',
235 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false) 246 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false)
236 ..addFlag('covariant-generics', 247 ..addFlag('covariant-generics',
237 help: 'Use covariant generics', defaultsTo: true) 248 help: 'Use covariant generics', defaultsTo: true)
238 ..addFlag('ignore-types', 249 ..addFlag('ignore-types',
239 help: 'Ignore types during codegen', defaultsTo: false) 250 help: 'Ignore types during codegen', defaultsTo: false)
240 ..addFlag('relaxed-casts', 251 ..addFlag('relaxed-casts',
241 help: 'Cast between Dart assignable types', defaultsTo: true) 252 help: 'Cast between Dart assignable types', defaultsTo: true)
242 ..addOption('nonnullable', 253 ..addOption('nonnullable',
243 abbr: 'n', 254 abbr: 'n',
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ..addFlag('help', abbr: 'h', help: 'Display this message') 289 ..addFlag('help', abbr: 'h', help: 'Display this message')
279 ..addFlag('force-compile', 290 ..addFlag('force-compile',
280 help: 'Compile code with static errors', defaultsTo: false) 291 help: 'Compile code with static errors', defaultsTo: false)
281 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') 292 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe')
282 ..addFlag('dump-info', 293 ..addFlag('dump-info',
283 abbr: 'i', help: 'Dump summary information', defaultsTo: false) 294 abbr: 'i', help: 'Dump summary information', defaultsTo: false)
284 ..addOption('dump-info-file', 295 ..addOption('dump-info-file',
285 abbr: 'f', 296 abbr: 'f',
286 help: 'Dump info json file (requires dump-info)', 297 help: 'Dump info json file (requires dump-info)',
287 defaultsTo: null); 298 defaultsTo: null);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698