OLD | NEW |
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 dev_compiler.src.options; | 6 library dev_compiler.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'; |
11 import 'package:cli_util/cli_util.dart' show getSdkDir; | 11 import 'package:cli_util/cli_util.dart' show getSdkDir; |
12 import 'package:dev_compiler/config.dart'; | 12 import 'package:dev_compiler/config.dart'; |
13 import 'package:logging/logging.dart' show Level; | 13 import 'package:logging/logging.dart' show Level; |
14 | 14 |
15 /// Options used by our TypeResolver. | 15 /// Options used by our TypeResolver. |
16 class ResolverOptions { | 16 class ResolverOptions { |
17 /// Whether to resolve 'package:' uris using the multi-package resolver. | 17 /// Whether to resolve 'package:' uris using the multi-package resolver. |
18 final bool useMultiPackage; | 18 final bool useMultiPackage; |
19 | 19 |
20 /// Package root when resolving 'package:' urls the standard way. | 20 /// Package root when resolving 'package:' urls the standard way. |
21 final String packageRoot; | 21 final String packageRoot; |
22 | 22 |
23 /// List of paths used for the multi-package resolver. | 23 /// List of paths used for the multi-package resolver. |
24 final List<String> packagePaths; | 24 final List<String> packagePaths; |
25 | 25 |
26 /// Whether to infer return types and field types from overriden members. | 26 /// Whether to infer return types and field types from overriden members. |
27 final bool inferFromOverrides; | 27 final bool inferFromOverrides; |
28 static const bool INFER_FROM_OVERRIDES_DEFAULT = false; | 28 static const inferFromOverridesDefault = false; |
29 | 29 |
30 /// Whether to infer types for consts and static fields by looking at | 30 /// Whether to infer types for consts and static fields by looking at |
31 /// identifiers on the RHS. For example, in a constant declaration like: | 31 /// identifiers on the RHS. For example, in a constant declaration like: |
32 /// | 32 /// |
33 /// const A = B; | 33 /// const A = B; |
34 /// | 34 /// |
35 /// We can infer the type of `A` based on the type of `B`. The current | 35 /// We can infer the type of `A` based on the type of `B`. The current |
36 /// implementation of this inference is limited and will only work if `B` is | 36 /// implementation of this inference is limited and will only work if `B` is |
37 /// defined in a different library than `A`. Because this might be surprising | 37 /// defined in a different library than `A`. Because this might be surprising |
38 /// to users, this is turned off by default. | 38 /// to users, this is turned off by default. |
39 final bool inferStaticsFromIdentifiers; | 39 final bool inferStaticsFromIdentifiers; |
| 40 static const inferStaticsFromIdentifiersDefault = false; |
40 | 41 |
41 /// Whether to ignore ordering issues and do a best effort in inference. When | 42 /// Whether to ignore ordering issues and do a best effort in inference. When |
42 /// false, inference of top-levels and statics is limited to only consider | 43 /// false, inference of top-levels and statics is limited to only consider |
43 /// expressions in the RHS for which the type is known precisely without | 44 /// expressions in the RHS for which the type is known precisely without |
44 /// regard of the ordering in which we apply inference. Turning this flag on | 45 /// regard of the ordering in which we apply inference. Turning this flag on |
45 /// will consider more expressions, including expressions where the RHS is | 46 /// will consider more expressions, including expressions where the RHS is |
46 /// another identifier (which [inferStaticsFromIdentifiers]). | 47 /// another identifier (which [inferStaticsFromIdentifiers]). |
47 /// | 48 /// |
48 /// Note: this option is experimental will be removed once we have a proper | 49 /// Note: this option is experimental will be removed once we have a proper |
49 /// implementation of inference in the future, which should handle all | 50 /// implementation of inference in the future, which should handle all |
50 /// ordering concerns. | 51 /// ordering concerns. |
51 final bool inferInNonStableOrder; | 52 final bool inferInNonStableOrder; |
| 53 static const inferInNonStableOrderDefault = false; |
52 | 54 |
53 /// Restrict inference of fields and top-levels to those that are final and | 55 /// Restrict inference of fields and top-levels to those that are final and |
54 /// const. | 56 /// const. |
55 final bool onlyInferConstsAndFinalFields; | 57 final bool onlyInferConstsAndFinalFields; |
| 58 static const onlyInferConstAndFinalFieldsDefault = false; |
56 | 59 |
57 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', | 60 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', |
58 this.packagePaths: const <String>[], | 61 this.packagePaths: const <String>[], |
59 this.inferFromOverrides: INFER_FROM_OVERRIDES_DEFAULT, | 62 this.inferFromOverrides: inferFromOverridesDefault, |
60 this.inferStaticsFromIdentifiers: false, | 63 this.inferStaticsFromIdentifiers: inferStaticsFromIdentifiersDefault, |
61 this.inferInNonStableOrder: false, | 64 this.inferInNonStableOrder: inferInNonStableOrderDefault, |
62 this.onlyInferConstsAndFinalFields: false}); | 65 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault}); |
63 } | 66 } |
64 | 67 |
65 // TODO(vsm): Merge RulesOptions and TypeOptions | 68 // TODO(vsm): Merge RulesOptions and TypeOptions |
66 /// Options used by our RestrictedRules. | 69 /// Options used by our RestrictedRules. |
67 class RulesOptions extends TypeOptions { | 70 class RulesOptions extends TypeOptions { |
68 /// Whether to allow casts in constant contexts. | 71 /// Whether to allow casts in constant contexts. |
69 final bool allowConstCasts; | 72 final bool allowConstCasts; |
70 | 73 |
71 /// Whether to use covariant generics | 74 /// Whether to use covariant generics |
72 final bool covariantGenerics; | 75 final bool covariantGenerics; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 final bool emitSourceMaps; | 203 final bool emitSourceMaps; |
201 | 204 |
202 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, | 205 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, |
203 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, | 206 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, |
204 this.forceCompile: false, this.formatOutput: false, | 207 this.forceCompile: false, this.formatOutput: false, |
205 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir, | 208 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir, |
206 this.outputDart: false, this.useColors: true, | 209 this.outputDart: false, this.useColors: true, |
207 this.covariantGenerics: true, this.relaxedCasts: true, | 210 this.covariantGenerics: true, this.relaxedCasts: true, |
208 this.useMultiPackage: false, this.packageRoot: 'packages/', | 211 this.useMultiPackage: false, this.packageRoot: 'packages/', |
209 this.packagePaths: const <String>[], | 212 this.packagePaths: const <String>[], |
210 this.inferFromOverrides: ResolverOptions.INFER_FROM_OVERRIDES_DEFAULT, | 213 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, |
211 this.inferStaticsFromIdentifiers: false, | 214 this.inferStaticsFromIdentifiers: ResolverOptions.inferStaticsFromIdentifi
ersDefault, |
212 this.inferInNonStableOrder: false, | 215 this.inferInNonStableOrder: ResolverOptions.inferInNonStableOrderDefault, |
213 this.onlyInferConstsAndFinalFields: false, | 216 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal
FieldsDefault, |
214 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, | 217 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, |
215 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, | 218 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, |
216 this.emitSourceMaps: true, this.entryPointFile: null, | 219 this.emitSourceMaps: true, this.entryPointFile: null, |
217 this.serverMode: false, this.port: 8080}); | 220 this.serverMode: false, this.port: 8080}); |
218 } | 221 } |
219 | 222 |
220 /// Parses options from the command-line | 223 /// Parses options from the command-line |
221 CompilerOptions parseOptions(List<String> argv) { | 224 CompilerOptions parseOptions(List<String> argv) { |
222 ArgResults args = argParser.parse(argv); | 225 ArgResults args = argParser.parse(argv); |
223 var levelName = args['log'].toUpperCase(); | 226 var levelName = args['log'].toUpperCase(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 help: 'Ignore types during codegen', defaultsTo: false) | 277 help: 'Ignore types during codegen', defaultsTo: false) |
275 ..addFlag('relaxed-casts', | 278 ..addFlag('relaxed-casts', |
276 help: 'Cast between Dart assignable types', defaultsTo: true) | 279 help: 'Cast between Dart assignable types', defaultsTo: true) |
277 ..addOption('nonnullable', | 280 ..addOption('nonnullable', |
278 abbr: 'n', | 281 abbr: 'n', |
279 help: 'Comma separated string of non-nullable types', | 282 help: 'Comma separated string of non-nullable types', |
280 defaultsTo: null) | 283 defaultsTo: null) |
281 ..addFlag('infer-from-overrides', | 284 ..addFlag('infer-from-overrides', |
282 help: 'Infer unspecified types of fields and return types from ' | 285 help: 'Infer unspecified types of fields and return types from ' |
283 'definitions in supertypes', | 286 'definitions in supertypes', |
284 defaultsTo: ResolverOptions.INFER_FROM_OVERRIDES_DEFAULT) | 287 defaultsTo: ResolverOptions.inferFromOverridesDefault) |
285 ..addFlag('infer-transitively', | 288 ..addFlag('infer-transitively', |
286 help: 'Infer consts/fields from definitions in other libraries', | 289 help: 'Infer consts/fields from definitions in other libraries', |
287 defaultsTo: false) | 290 defaultsTo: ResolverOptions.inferStaticsFromIdentifiersDefault) |
288 ..addFlag('infer-only-finals', | 291 ..addFlag('infer-only-finals', |
289 help: 'Do not infer non-const or non-final fields', defaultsTo: false) | 292 help: 'Do not infer non-const or non-final fields', |
| 293 defaultsTo: ResolverOptions.onlyInferConstAndFinalFieldsDefault) |
290 ..addFlag('infer-eagerly', | 294 ..addFlag('infer-eagerly', |
291 help: 'experimental: allows a non-stable order of transitive inference on' | 295 help: 'experimental: allows a non-stable order of transitive inference on' |
292 ' consts and fields. This is used to test for possible inference with a ' | 296 ' consts and fields. This is used to test for possible inference with a ' |
293 'proper implementation in the future.', defaultsTo: false) | 297 'proper implementation in the future.', |
| 298 defaultsTo: ResolverOptions.inferInNonStableOrderDefault) |
294 | 299 |
295 // input/output options | 300 // input/output options |
296 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null) | 301 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null) |
297 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) | 302 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) |
298 ..addFlag('dart-gen', | 303 ..addFlag('dart-gen', |
299 abbr: 'd', help: 'Generate dart output', defaultsTo: false) | 304 abbr: 'd', help: 'Generate dart output', defaultsTo: false) |
300 ..addFlag('dart-gen-fmt', | 305 ..addFlag('dart-gen-fmt', |
301 help: 'Generate readable dart output', defaultsTo: true) | 306 help: 'Generate readable dart output', defaultsTo: true) |
302 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null) | 307 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null) |
303 ..addOption('package-root', | 308 ..addOption('package-root', |
(...skipping 16 matching lines...) Expand all Loading... |
320 defaultsTo: '8080') | 325 defaultsTo: '8080') |
321 ..addFlag('force-compile', | 326 ..addFlag('force-compile', |
322 help: 'Compile code with static errors', defaultsTo: false) | 327 help: 'Compile code with static errors', defaultsTo: false) |
323 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') | 328 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') |
324 ..addFlag('dump-info', | 329 ..addFlag('dump-info', |
325 abbr: 'i', help: 'Dump summary information', defaultsTo: false) | 330 abbr: 'i', help: 'Dump summary information', defaultsTo: false) |
326 ..addOption('dump-info-file', | 331 ..addOption('dump-info-file', |
327 abbr: 'f', | 332 abbr: 'f', |
328 help: 'Dump info json file (requires dump-info)', | 333 help: 'Dump info json file (requires dump-info)', |
329 defaultsTo: null); | 334 defaultsTo: null); |
OLD | NEW |