OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library fasta.compiler_context; |
| 6 |
| 7 import 'dart:async' show |
| 8 Zone, |
| 9 runZoned; |
| 10 |
| 11 import 'package:kernel/ast.dart' show |
| 12 Source; |
| 13 |
| 14 import 'compiler_command_line.dart' show |
| 15 CompilerCommandLine; |
| 16 |
| 17 final Object compilerContextKey = new Object(); |
| 18 |
| 19 final CompilerContext rootContext = |
| 20 new CompilerContext(CompilerCommandLine.forRootContext()); |
| 21 |
| 22 class CompilerContext { |
| 23 final CompilerCommandLine options; |
| 24 |
| 25 final Map<String, Source> uriToSource = <String, Source>{}; |
| 26 |
| 27 CompilerContext(this.options); |
| 28 |
| 29 static CompilerContext get current { |
| 30 return Zone.current[compilerContextKey] ?? rootContext; |
| 31 } |
| 32 |
| 33 /// Perform [action] in a [Zone] where [cl] will be available as |
| 34 /// `CompilerContext.current.options`. |
| 35 static dynamic withGlobalOptions(CompilerCommandLine cl, |
| 36 dynamic action(CompilerContext c)) { |
| 37 CompilerContext c = new CompilerContext(cl); |
| 38 return runZoned(() => action(c), zoneValues: {compilerContextKey: c}); |
| 39 } |
| 40 } |
OLD | NEW |