| 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 Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'package:kernel/ast.dart' | 9 import 'package:kernel/ast.dart' |
| 10 show | 10 show |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 import '../deprecated_problems.dart' | 47 import '../deprecated_problems.dart' |
| 48 show | 48 show |
| 49 deprecated_formatUnexpected, | 49 deprecated_formatUnexpected, |
| 50 deprecated_InputError, | 50 deprecated_InputError, |
| 51 reportCrash, | 51 reportCrash, |
| 52 resetCrashReporting; | 52 resetCrashReporting; |
| 53 | 53 |
| 54 import '../dill/dill_target.dart' show DillTarget; | 54 import '../dill/dill_target.dart' show DillTarget; |
| 55 | 55 |
| 56 import '../messages.dart' show LocatedMessage; | 56 import '../messages.dart' |
| 57 show |
| 58 LocatedMessage, |
| 59 messageConstConstructorNonFinalField, |
| 60 messageConstConstructorNonFinalFieldCause, |
| 61 templateSuperclassHasNoDefaultConstructor; |
| 57 | 62 |
| 58 import '../problems.dart' show unhandled; | 63 import '../problems.dart' show unhandled; |
| 59 | 64 |
| 60 import '../source/source_class_builder.dart' show SourceClassBuilder; | 65 import '../source/source_class_builder.dart' show SourceClassBuilder; |
| 61 | 66 |
| 62 import '../source/source_loader.dart' show SourceLoader; | 67 import '../source/source_loader.dart' show SourceLoader; |
| 63 | 68 |
| 64 import '../target_implementation.dart' show TargetImplementation; | 69 import '../target_implementation.dart' show TargetImplementation; |
| 65 | 70 |
| 66 import '../uri_translator.dart' show UriTranslator; | 71 import '../uri_translator.dart' show UriTranslator; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 KernelTarget( | 115 KernelTarget( |
| 111 this.fileSystem, DillTarget dillTarget, UriTranslator uriTranslator, | 116 this.fileSystem, DillTarget dillTarget, UriTranslator uriTranslator, |
| 112 [Map<String, Source> uriToSource]) | 117 [Map<String, Source> uriToSource]) |
| 113 : dillTarget = dillTarget, | 118 : dillTarget = dillTarget, |
| 114 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, | 119 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, |
| 115 super(dillTarget.ticker, uriTranslator, dillTarget.backendTarget) { | 120 super(dillTarget.ticker, uriTranslator, dillTarget.backendTarget) { |
| 116 resetCrashReporting(); | 121 resetCrashReporting(); |
| 117 loader = createLoader(); | 122 loader = createLoader(); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void deprecated_addError(file, int charOffset, String message) { | |
| 121 Uri uri = file is String ? Uri.parse(file) : file; | |
| 122 deprecated_InputError error = | |
| 123 new deprecated_InputError(uri, charOffset, message); | |
| 124 String formatterMessage = error.deprecated_format(); | |
| 125 print(formatterMessage); | |
| 126 errors.add(formatterMessage); | |
| 127 } | |
| 128 | |
| 129 SourceLoader<Library> createLoader() => | 125 SourceLoader<Library> createLoader() => |
| 130 new SourceLoader<Library>(fileSystem, this); | 126 new SourceLoader<Library>(fileSystem, this); |
| 131 | 127 |
| 132 void addSourceInformation( | 128 void addSourceInformation( |
| 133 Uri uri, List<int> lineStarts, List<int> sourceCode) { | 129 Uri uri, List<int> lineStarts, List<int> sourceCode) { |
| 134 String fileUri = relativizeUri(uri); | 130 String fileUri = relativizeUri(uri); |
| 135 uriToSource[fileUri] = new Source(lineStarts, sourceCode); | 131 uriToSource[fileUri] = new Source(lineStarts, sourceCode); |
| 136 } | 132 } |
| 137 | 133 |
| 138 void read(Uri uri) { | 134 void read(Uri uri) { |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 MemberBuilder constructorBuilder = member; | 545 MemberBuilder constructorBuilder = member; |
| 550 Constructor constructor = constructorBuilder.target; | 546 Constructor constructor = constructorBuilder.target; |
| 551 if (!constructorBuilder.isRedirectingGenerativeConstructor) { | 547 if (!constructorBuilder.isRedirectingGenerativeConstructor) { |
| 552 /// >If no superinitializer is provided, an implicit superinitializer | 548 /// >If no superinitializer is provided, an implicit superinitializer |
| 553 /// >of the form super() is added at the end of k’s initializer list, | 549 /// >of the form super() is added at the end of k’s initializer list, |
| 554 /// >unless the enclosing class is class Object. | 550 /// >unless the enclosing class is class Object. |
| 555 if (constructor.initializers.isEmpty) { | 551 if (constructor.initializers.isEmpty) { |
| 556 superTarget ??= defaultSuperConstructor(cls); | 552 superTarget ??= defaultSuperConstructor(cls); |
| 557 Initializer initializer; | 553 Initializer initializer; |
| 558 if (superTarget == null) { | 554 if (superTarget == null) { |
| 559 deprecated_addError( | 555 builder.addCompileTimeError( |
| 560 constructor.enclosingClass.fileUri, | 556 templateSuperclassHasNoDefaultConstructor |
| 561 constructor.fileOffset, | 557 .withArguments(cls.superclass.name), |
| 562 "${cls.superclass.name} has no constructor that takes no" | 558 constructor.fileOffset); |
| 563 " arguments."); | |
| 564 initializer = new InvalidInitializer(); | 559 initializer = new InvalidInitializer(); |
| 565 } else { | 560 } else { |
| 566 initializer = | 561 initializer = |
| 567 new SuperInitializer(superTarget, new Arguments.empty()); | 562 new SuperInitializer(superTarget, new Arguments.empty()); |
| 568 } | 563 } |
| 569 constructor.initializers.add(initializer); | 564 constructor.initializers.add(initializer); |
| 570 initializer.parent = constructor; | 565 initializer.parent = constructor; |
| 571 } | 566 } |
| 572 if (constructor.function.body == null) { | 567 if (constructor.function.body == null) { |
| 573 /// >If a generative constructor c is not a redirecting constructor | 568 /// >If a generative constructor c is not a redirecting constructor |
| 574 /// >and no body is provided, then c implicitly has an empty body {}. | 569 /// >and no body is provided, then c implicitly has an empty body {}. |
| 575 /// We use an empty statement instead. | 570 /// We use an empty statement instead. |
| 576 constructor.function.body = new EmptyStatement(); | 571 constructor.function.body = new EmptyStatement(); |
| 577 constructor.function.body.parent = constructor.function; | 572 constructor.function.body.parent = constructor.function; |
| 578 } | 573 } |
| 579 List<FieldInitializer> myFieldInitializers = <FieldInitializer>[]; | 574 List<FieldInitializer> myFieldInitializers = <FieldInitializer>[]; |
| 580 for (Initializer initializer in constructor.initializers) { | 575 for (Initializer initializer in constructor.initializers) { |
| 581 if (initializer is FieldInitializer) { | 576 if (initializer is FieldInitializer) { |
| 582 myFieldInitializers.add(initializer); | 577 myFieldInitializers.add(initializer); |
| 583 } | 578 } |
| 584 } | 579 } |
| 585 fieldInitializers[constructor] = myFieldInitializers; | 580 fieldInitializers[constructor] = myFieldInitializers; |
| 586 if (constructor.isConst && nonFinalFields.isNotEmpty) { | 581 if (constructor.isConst && nonFinalFields.isNotEmpty) { |
| 587 deprecated_addError( | 582 builder.addCompileTimeError( |
| 588 constructor.enclosingClass.fileUri, | 583 messageConstConstructorNonFinalField, constructor.fileOffset); |
| 589 constructor.fileOffset, | |
| 590 "Constructor is marked 'const' so all fields must be final."); | |
| 591 for (Field field in nonFinalFields) { | 584 for (Field field in nonFinalFields) { |
| 592 deprecated_addError( | 585 builder.addCompileTimeError( |
| 593 constructor.enclosingClass.fileUri, | 586 messageConstConstructorNonFinalFieldCause, field.fileOffset); |
| 594 field.fileOffset, | |
| 595 "Field isn't final, but constructor is 'const'."); | |
| 596 } | 587 } |
| 597 nonFinalFields.clear(); | 588 nonFinalFields.clear(); |
| 598 } | 589 } |
| 599 } | 590 } |
| 600 }); | 591 }); |
| 601 Set<Field> initializedFields; | 592 Set<Field> initializedFields; |
| 602 fieldInitializers.forEach( | 593 fieldInitializers.forEach( |
| 603 (Constructor constructor, List<FieldInitializer> initializers) { | 594 (Constructor constructor, List<FieldInitializer> initializers) { |
| 604 Iterable<Field> fields = initializers.map((i) => i.field); | 595 Iterable<Field> fields = initializers.map((i) => i.field); |
| 605 if (initializedFields == null) { | 596 if (initializedFields == null) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 } | 655 } |
| 665 for (Constructor constructor in superclass.constructors) { | 656 for (Constructor constructor in superclass.constructors) { |
| 666 if (constructor.name.name.isEmpty) { | 657 if (constructor.name.name.isEmpty) { |
| 667 return constructor.function.requiredParameterCount == 0 | 658 return constructor.function.requiredParameterCount == 0 |
| 668 ? constructor | 659 ? constructor |
| 669 : null; | 660 : null; |
| 670 } | 661 } |
| 671 } | 662 } |
| 672 return null; | 663 return null; |
| 673 } | 664 } |
| OLD | NEW |