| OLD | NEW |
| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 builder.interfaces = null; | 200 builder.interfaces = null; |
| 201 } | 201 } |
| 202 | 202 |
| 203 Future<Program> handleInputError(Uri uri, InputError error, | 203 Future<Program> handleInputError(Uri uri, InputError error, |
| 204 {bool isFullProgram}) { | 204 {bool isFullProgram}) { |
| 205 if (error != null) { | 205 if (error != null) { |
| 206 String message = error.format(); | 206 String message = error.format(); |
| 207 print(message); | 207 print(message); |
| 208 errors.add(message); | 208 errors.add(message); |
| 209 } | 209 } |
| 210 program = erroneousProgram(); | 210 program = erroneousProgram(isFullProgram); |
| 211 return uri == null | 211 return uri == null |
| 212 ? new Future<Program>.value(program) | 212 ? new Future<Program>.value(program) |
| 213 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); | 213 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); |
| 214 } | 214 } |
| 215 | 215 |
| 216 Future<Program> writeProgram(Uri uri, AstKind astKind) async { | 216 Future<Program> writeProgram(Uri uri, AstKind astKind) async { |
| 217 if (loader.first == null) return null; | 217 if (loader.first == null) return null; |
| 218 if (errors.isNotEmpty) { | 218 if (errors.isNotEmpty) { |
| 219 return handleInputError(uri, null, isFullProgram: true); | 219 return handleInputError(uri, null, isFullProgram: true); |
| 220 } | 220 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 program = link(new List<Library>.from(loader.libraries)); | 258 program = link(new List<Library>.from(loader.libraries)); |
| 259 if (uri == null) return program; | 259 if (uri == null) return program; |
| 260 return await writeLinkedProgram(uri, program, isFullProgram: false); | 260 return await writeLinkedProgram(uri, program, isFullProgram: false); |
| 261 } on InputError catch (e) { | 261 } on InputError catch (e) { |
| 262 return handleInputError(uri, e, isFullProgram: false); | 262 return handleInputError(uri, e, isFullProgram: false); |
| 263 } catch (e, s) { | 263 } catch (e, s) { |
| 264 return reportCrash(e, s, loader?.currentUriForCrashReporting); | 264 return reportCrash(e, s, loader?.currentUriForCrashReporting); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 Program erroneousProgram() { | 268 Program erroneousProgram(bool isFullProgram) { |
| 269 Uri uri = loader.first?.uri ?? Uri.parse("error:error"); | 269 Uri uri = loader.first?.uri ?? Uri.parse("error:error"); |
| 270 KernelLibraryBuilder library = new KernelLibraryBuilder(uri, loader); | 270 KernelLibraryBuilder library = new KernelLibraryBuilder(uri, loader); |
| 271 KernelProcedureBuilder mainBuilder = new KernelProcedureBuilder(null, 0, | |
| 272 null, "main", null, null, AsyncMarker.Sync, ProcedureKind.Method); | |
| 273 library.addBuilder(mainBuilder.name, mainBuilder); | |
| 274 loader.first = library; | 271 loader.first = library; |
| 275 mainBuilder.body = new ExpressionStatement( | 272 if (isFullProgram) { |
| 276 new Throw(new StringLiteral("${errors.join('\n')}"))); | 273 // If this is an outline, we shouldn't add an executable main |
| 274 // method. Similarly considerations apply to separate compilation. It |
| 275 // could also make sense to add a way to mark .dill files as having |
| 276 // compile-time errors. |
| 277 KernelProcedureBuilder mainBuilder = new KernelProcedureBuilder(null, 0, |
| 278 null, "main", null, null, AsyncMarker.Sync, ProcedureKind.Method); |
| 279 library.addBuilder(mainBuilder.name, mainBuilder); |
| 280 mainBuilder.body = new ExpressionStatement( |
| 281 new Throw(new StringLiteral("${errors.join('\n')}"))); |
| 282 } |
| 277 library.build(); | 283 library.build(); |
| 278 return link(<Library>[library.library]); | 284 return link(<Library>[library.library]); |
| 279 } | 285 } |
| 280 | 286 |
| 281 /// Creates a program by combining [libraries] with the libraries of | 287 /// Creates a program by combining [libraries] with the libraries of |
| 282 /// `dillTarget.loader.program`. | 288 /// `dillTarget.loader.program`. |
| 283 Program link(List<Library> libraries) { | 289 Program link(List<Library> libraries) { |
| 284 Map<String, Source> uriToSource = <String, Source>{}; | 290 Map<String, Source> uriToSource = <String, Source>{}; |
| 285 | 291 |
| 286 // for (Library library in libraries) { | 292 // for (Library library in libraries) { |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 superclass = superclass.superclass; | 585 superclass = superclass.superclass; |
| 580 } | 586 } |
| 581 for (Constructor constructor in superclass.constructors) { | 587 for (Constructor constructor in superclass.constructors) { |
| 582 if (constructor.name.name.isEmpty) { | 588 if (constructor.name.name.isEmpty) { |
| 583 return constructor.function.requiredParameterCount == 0 ? | 589 return constructor.function.requiredParameterCount == 0 ? |
| 584 constructor : null; | 590 constructor : null; |
| 585 } | 591 } |
| 586 } | 592 } |
| 587 return null; | 593 return null; |
| 588 } | 594 } |
| OLD | NEW |