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

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

Issue 2704753002: Implement line and column numbers. (Closed)
Patch Set: Created 3 years, 10 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.kernel_target; 5 library fasta.kernel_target;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 Future; 8 Future;
9 9
10 import 'dart:io' show 10 import 'dart:io' show
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 import '../ast_kind.dart' show 69 import '../ast_kind.dart' show
70 AstKind; 70 AstKind;
71 71
72 import '../errors.dart' show 72 import '../errors.dart' show
73 InputError, 73 InputError,
74 internalError, 74 internalError,
75 reportCrash, 75 reportCrash,
76 resetCrashReporting; 76 resetCrashReporting;
77 77
78 import '../util/relativize.dart' show
79 relativizeUri;
80
81 import '../compiler_context.dart' show
82 CompilerContext;
83
78 import 'kernel_builder.dart' show 84 import 'kernel_builder.dart' show
79 Builder, 85 Builder,
80 ClassBuilder, 86 ClassBuilder,
81 DynamicTypeBuilder, 87 DynamicTypeBuilder,
82 InvalidTypeBuilder, 88 InvalidTypeBuilder,
83 KernelClassBuilder, 89 KernelClassBuilder,
84 KernelLibraryBuilder, 90 KernelLibraryBuilder,
85 KernelNamedTypeBuilder, 91 KernelNamedTypeBuilder,
86 KernelProcedureBuilder, 92 KernelProcedureBuilder,
87 LibraryBuilder, 93 LibraryBuilder,
88 MixinApplicationBuilder, 94 MixinApplicationBuilder,
89 NamedMixinApplicationBuilder, 95 NamedMixinApplicationBuilder,
90 NamedTypeBuilder, 96 NamedTypeBuilder,
91 TypeBuilder; 97 TypeBuilder;
92 98
93 class KernelTarget extends TargetImplementation { 99 class KernelTarget extends TargetImplementation {
94 final DillTarget dillTarget; 100 final DillTarget dillTarget;
101
102 /// Shared with [CompilerContext].
103 final Map<String, Source> uriToSource;
104
95 SourceLoader<Library> loader; 105 SourceLoader<Library> loader;
96 Program program; 106 Program program;
97 107
98 final List errors = []; 108 final List errors = [];
99 109
100 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator) 110 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator,
111 [Map<String, Source> uriToSource])
101 : dillTarget = dillTarget, 112 : dillTarget = dillTarget,
113 uriToSource = uriToSource ?? CompilerContext.current.uriToSource,
102 super(dillTarget.ticker, uriTranslator) { 114 super(dillTarget.ticker, uriTranslator) {
103 resetCrashReporting(); 115 resetCrashReporting();
104 loader = new SourceLoader<Library>(this); 116 loader = new SourceLoader<Library>(this);
105 } 117 }
106 118
119 void addLineStarts(Uri uri, List<int> lineStarts) {
120 String fileUri = relativizeUri(uri);
121 uriToSource[fileUri] = new Source(lineStarts, fileUri);
122 }
123
107 void read(Uri uri) { 124 void read(Uri uri) {
108 loader.read(uri); 125 loader.read(uri);
109 } 126 }
110 127
111 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { 128 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) {
112 if (dillTarget.isLoaded) { 129 if (dillTarget.isLoaded) {
113 var builder = dillTarget.loader.builders[uri]; 130 var builder = dillTarget.loader.builders[uri];
114 if (builder != null) { 131 if (builder != null) {
115 return builder; 132 return builder;
116 } 133 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } else { 241 } else {
225 loader.computeHierarchy(program); 242 loader.computeHierarchy(program);
226 } 243 }
227 await loader.buildBodies(astKind); 244 await loader.buildBodies(astKind);
228 loader.finishStaticInvocations(); 245 loader.finishStaticInvocations();
229 finishAllConstructors(); 246 finishAllConstructors();
230 loader.finishNativeMethods(); 247 loader.finishNativeMethods();
231 transformMixinApplications(); 248 transformMixinApplications();
232 // TODO(ahe): Don't call this from two different places. 249 // TODO(ahe): Don't call this from two different places.
233 setup_builtin_library.transformProgram(program); 250 setup_builtin_library.transformProgram(program);
234 errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format())); 251 errors.addAll(
252 loader.collectCompileTimeErrors().map((e) => e.format()));
235 if (errors.isNotEmpty) { 253 if (errors.isNotEmpty) {
236 return handleInputError(uri, null, isFullProgram: true); 254 return handleInputError(uri, null, isFullProgram: true);
237 } 255 }
238 if (uri == null) return program; 256 if (uri == null) return program;
239 return await writeLinkedProgram(uri, program, isFullProgram: true); 257 return await writeLinkedProgram(uri, program, isFullProgram: true);
240 } on InputError catch (e) { 258 } on InputError catch (e) {
241 return handleInputError(uri, e, isFullProgram: true); 259 return handleInputError(uri, e, isFullProgram: true);
242 } catch (e, s) { 260 } catch (e, s) {
243 return reportCrash(e, s, loader?.currentUriForCrashReporting); 261 return reportCrash(e, s, loader?.currentUriForCrashReporting);
244 } 262 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // that used when there's no fileUri on an element. Instead, ensure all 328 // that used when there's no fileUri on an element. Instead, ensure all
311 // elements have a fileUri. 329 // elements have a fileUri.
312 uriToSource[""] = new Source(<int>[0], ""); 330 uriToSource[""] = new Source(<int>[0], "");
313 Program program = new Program(libraries, uriToSource); 331 Program program = new Program(libraries, uriToSource);
314 if (loader.first != null) { 332 if (loader.first != null) {
315 Builder builder = loader.first.members["main"]; 333 Builder builder = loader.first.members["main"];
316 if (builder is KernelProcedureBuilder) { 334 if (builder is KernelProcedureBuilder) {
317 program.mainMethod = builder.procedure; 335 program.mainMethod = builder.procedure;
318 } 336 }
319 } 337 }
320 setup_builtin_library.transformProgram(program); 338 if (errors.isEmpty || dillTarget.isLoaded) {
339 setup_builtin_library.transformProgram(program);
340 }
321 ticker.logMs("Linked program"); 341 ticker.logMs("Linked program");
322 return program; 342 return program;
323 } 343 }
324 344
325 Future<Program> writeLinkedProgram(Uri uri, Program program, 345 Future<Program> writeLinkedProgram(Uri uri, Program program,
326 {bool isFullProgram}) async { 346 {bool isFullProgram}) async {
327 File output = new File.fromUri(uri); 347 File output = new File.fromUri(uri);
328 IOSink sink = output.openWrite(); 348 IOSink sink = output.openWrite();
329 try { 349 try {
330 new BinaryPrinter(sink).writeProgramFile(program); 350 new BinaryPrinter(sink).writeProgramFile(program);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 superclass = superclass.superclass; 601 superclass = superclass.superclass;
582 } 602 }
583 for (Constructor constructor in superclass.constructors) { 603 for (Constructor constructor in superclass.constructors) {
584 if (constructor.name.name.isEmpty) { 604 if (constructor.name.name.isEmpty) {
585 return constructor.function.requiredParameterCount == 0 ? 605 return constructor.function.requiredParameterCount == 0 ?
586 constructor : null; 606 constructor : null;
587 } 607 }
588 } 608 }
589 return null; 609 return null;
590 } 610 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698