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

Side by Side Diff: pkg/front_end/lib/src/fasta/compiler_context.dart

Issue 2980033004: Throw if there is no compiler context available (Closed)
Patch Set: cl comments, handle validate and deprecated_InputError Created 3 years, 5 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) 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'; 9 import 'package:front_end/file_system.dart';
10 import 'package:front_end/physical_file_system.dart'; 10 import 'package:front_end/physical_file_system.dart';
11 import 'package:front_end/src/fasta/fasta_codes.dart';
11 import 'package:kernel/ast.dart' show Source; 12 import 'package:kernel/ast.dart' show Source;
12 13
13 import 'compiler_command_line.dart' show CompilerCommandLine; 14 import 'compiler_command_line.dart' show CompilerCommandLine;
14 15
15 import 'colors.dart' show computeEnableColors; 16 import 'colors.dart' show computeEnableColors;
16 17
17 import 'fasta_codes.dart' show LocatedMessage, Message; 18 import 'fasta_codes.dart' show LocatedMessage, Message;
18 19
19 import 'severity.dart' show Severity; 20 import 'severity.dart' show Severity;
20 21
21 final Object compilerContextKey = new Object(); 22 final Object compilerContextKey = new Object();
22 23
23 final CompilerContext rootContext =
24 new CompilerContext(CompilerCommandLine.forRootContext());
25
26 class CompilerContext { 24 class CompilerContext {
27 final FileSystem fileSystem = PhysicalFileSystem.instance; 25 final FileSystem fileSystem = PhysicalFileSystem.instance;
28 26
29 final CompilerCommandLine options; 27 final CompilerCommandLine options;
30 28
31 final Map<String, Source> uriToSource = <String, Source>{}; 29 final Map<String, Source> uriToSource = <String, Source>{};
32 30
33 bool enableColorsCached = null; 31 bool enableColorsCached = null;
34 32
35 CompilerContext(this.options); 33 CompilerContext(this.options);
(...skipping 16 matching lines...) Expand all
52 String format(LocatedMessage message, Severity severity) { 50 String format(LocatedMessage message, Severity severity) {
53 return options.format(message, severity); 51 return options.format(message, severity);
54 } 52 }
55 53
56 /// Format [message] as a text string that can be included in generated code. 54 /// Format [message] as a text string that can be included in generated code.
57 String formatWithoutLocation(Message message, Severity severity) { 55 String formatWithoutLocation(Message message, Severity severity) {
58 return options.formatWithoutLocation(message, severity); 56 return options.formatWithoutLocation(message, severity);
59 } 57 }
60 58
61 static CompilerContext get current { 59 static CompilerContext get current {
62 return Zone.current[compilerContextKey] ?? rootContext; 60 var context = Zone.current[compilerContextKey];
61 if (context == null) {
62 // Note: we throw directly and don't use internalProblem, because
63 // internalProblem depends on having a compiler context available.
64 var message = messageInternalProblemMissingContext.message;
65 var tip = messageInternalProblemMissingContext.tip;
66 throw "Internal problem: $message\nTip: $tip";
67 }
68 return context;
63 } 69 }
64 70
65 /// Perform [action] in a [Zone] where [cl] will be available as 71 /// Perform [action] in a [Zone] where [cl] will be available as
66 /// `CompilerContext.current.options`. 72 /// `CompilerContext.current.options`.
67 static dynamic withGlobalOptions( 73 static dynamic withGlobalOptions(
68 CompilerCommandLine cl, dynamic action(CompilerContext c)) { 74 CompilerCommandLine cl, dynamic action(CompilerContext c)) {
69 CompilerContext c = new CompilerContext(cl); 75 CompilerContext c = new CompilerContext(cl);
70 return runZoned(() => action(c), zoneValues: {compilerContextKey: c}); 76 return runZoned(() => action(c), zoneValues: {compilerContextKey: c});
71 } 77 }
72 78
73 static bool get enableColors { 79 static bool get enableColors {
74 return current.enableColorsCached ??= computeEnableColors(current); 80 return current.enableColorsCached ??= computeEnableColors(current);
75 } 81 }
76 } 82 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/compiler_command_line.dart ('k') | pkg/front_end/lib/src/fasta/fasta.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698