Index: pkg/front_end/lib/src/fasta/compiler_context.dart |
diff --git a/pkg/front_end/lib/src/fasta/compiler_context.dart b/pkg/front_end/lib/src/fasta/compiler_context.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8894017fda879124f1be1182009b30aaf5a56a3 |
--- /dev/null |
+++ b/pkg/front_end/lib/src/fasta/compiler_context.dart |
@@ -0,0 +1,40 @@ |
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library fasta.compiler_context; |
+ |
+import 'dart:async' show |
+ Zone, |
+ runZoned; |
+ |
+import 'package:kernel/ast.dart' show |
+ Source; |
+ |
+import 'compiler_command_line.dart' show |
+ CompilerCommandLine; |
+ |
+final Object compilerContextKey = new Object(); |
+ |
+final CompilerContext rootContext = |
+ new CompilerContext(CompilerCommandLine.forRootContext()); |
+ |
+class CompilerContext { |
+ final CompilerCommandLine options; |
+ |
+ final Map<String, Source> uriToSource = <String, Source>{}; |
+ |
+ CompilerContext(this.options); |
+ |
+ static CompilerContext get current { |
+ return Zone.current[compilerContextKey] ?? rootContext; |
+ } |
+ |
+ /// Perform [action] in a [Zone] where [cl] will be available as |
+ /// `CompilerContext.current.options`. |
+ static dynamic withGlobalOptions(CompilerCommandLine cl, |
+ dynamic action(CompilerContext c)) { |
+ CompilerContext c = new CompilerContext(cl); |
+ return runZoned(() => action(c), zoneValues: {compilerContextKey: c}); |
+ } |
+} |