| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 library fasta.compiler_context; | 5 library fasta.compiler_context; |
| 6 | 6 |
| 7 import 'dart:async' show Zone, runZoned; | 7 import 'dart:async' show Zone, runZoned; |
| 8 | 8 |
| 9 import 'package:front_end/file_system.dart'; |
| 10 import 'package:front_end/physical_file_system.dart'; |
| 9 import 'package:kernel/ast.dart' show Source; | 11 import 'package:kernel/ast.dart' show Source; |
| 10 | 12 |
| 11 import 'compiler_command_line.dart' show CompilerCommandLine; | 13 import 'compiler_command_line.dart' show CompilerCommandLine; |
| 12 | 14 |
| 13 import 'colors.dart' show computeEnableColors; | 15 import 'colors.dart' show computeEnableColors; |
| 14 | 16 |
| 15 final Object compilerContextKey = new Object(); | 17 final Object compilerContextKey = new Object(); |
| 16 | 18 |
| 17 final CompilerContext rootContext = | 19 final CompilerContext rootContext = |
| 18 new CompilerContext(CompilerCommandLine.forRootContext()); | 20 new CompilerContext(CompilerCommandLine.forRootContext()); |
| 19 | 21 |
| 20 class CompilerContext { | 22 class CompilerContext { |
| 23 final FileSystem fileSystem = PhysicalFileSystem.instance; |
| 21 final CompilerCommandLine options; | 24 final CompilerCommandLine options; |
| 22 | 25 |
| 23 final Map<String, Source> uriToSource = <String, Source>{}; | 26 final Map<String, Source> uriToSource = <String, Source>{}; |
| 24 | 27 |
| 25 bool enableColorsCached = null; | 28 bool enableColorsCached = null; |
| 26 | 29 |
| 27 CompilerContext(this.options); | 30 CompilerContext(this.options); |
| 28 | 31 |
| 29 static CompilerContext get current { | 32 static CompilerContext get current { |
| 30 return Zone.current[compilerContextKey] ?? rootContext; | 33 return Zone.current[compilerContextKey] ?? rootContext; |
| 31 } | 34 } |
| 32 | 35 |
| 33 /// Perform [action] in a [Zone] where [cl] will be available as | 36 /// Perform [action] in a [Zone] where [cl] will be available as |
| 34 /// `CompilerContext.current.options`. | 37 /// `CompilerContext.current.options`. |
| 35 static dynamic withGlobalOptions( | 38 static dynamic withGlobalOptions( |
| 36 CompilerCommandLine cl, dynamic action(CompilerContext c)) { | 39 CompilerCommandLine cl, dynamic action(CompilerContext c)) { |
| 37 CompilerContext c = new CompilerContext(cl); | 40 CompilerContext c = new CompilerContext(cl); |
| 38 return runZoned(() => action(c), zoneValues: {compilerContextKey: c}); | 41 return runZoned(() => action(c), zoneValues: {compilerContextKey: c}); |
| 39 } | 42 } |
| 40 | 43 |
| 41 static bool get enableColors { | 44 static bool get enableColors { |
| 42 return current.enableColorsCached ??= computeEnableColors(current); | 45 return current.enableColorsCached ??= computeEnableColors(current); |
| 43 } | 46 } |
| 44 } | 47 } |
| OLD | NEW |