| 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.target_implementation; | 5 library fasta.target_implementation; |
| 6 | 6 |
| 7 import 'builder/builder.dart' show | 7 import 'builder/builder.dart' show |
| 8 Builder, | 8 Builder, |
| 9 ClassBuilder, | 9 ClassBuilder, |
| 10 LibraryBuilder; | 10 LibraryBuilder; |
| 11 | 11 |
| 12 import 'loader.dart' show | 12 import 'loader.dart' show |
| 13 Loader; | 13 Loader; |
| 14 | 14 |
| 15 import 'target.dart' show | 15 import 'target.dart' show |
| 16 Target; | 16 Target; |
| 17 | 17 |
| 18 import 'ticker.dart' show | 18 import 'ticker.dart' show |
| 19 Ticker; | 19 Ticker; |
| 20 | 20 |
| 21 import 'translate_uri.dart' show | 21 import 'translate_uri.dart' show |
| 22 TranslateUri; | 22 TranslateUri; |
| 23 | 23 |
| 24 /// Provides the implementation details used by a loader for a target. | 24 /// Provides the implementation details used by a loader for a target. |
| 25 abstract class TargetImplementation extends Target { | 25 abstract class TargetImplementation extends Target { |
| 26 final TranslateUri uriTranslator; | 26 final TranslateUri uriTranslator; |
| 27 Builder cachedCompileTimeError; | 27 Builder cachedCompileTimeError; |
| 28 Builder cachedNativeAnnotation; |
| 28 | 29 |
| 29 TargetImplementation(Ticker ticker, this.uriTranslator) | 30 TargetImplementation(Ticker ticker, this.uriTranslator) |
| 30 : super(ticker); | 31 : super(ticker); |
| 31 | 32 |
| 32 /// Creates a [LibraryBuilder] corresponding to [uri], if one doesn't exist | 33 /// Creates a [LibraryBuilder] corresponding to [uri], if one doesn't exist |
| 33 /// already. | 34 /// already. |
| 34 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri); | 35 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri); |
| 35 | 36 |
| 36 /// Add the classes extended or implemented directly by [cls] to [set]. | 37 /// Add the classes extended or implemented directly by [cls] to [set]. |
| 37 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set); | 38 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set); |
| 38 | 39 |
| 39 /// Returns all classes that will be included in the resulting program. | 40 /// Returns all classes that will be included in the resulting program. |
| 40 List<ClassBuilder> collectAllClasses(); | 41 List<ClassBuilder> collectAllClasses(); |
| 41 | 42 |
| 42 /// The class [cls] is involved in a cyclic definition. This method should | 43 /// The class [cls] is involved in a cyclic definition. This method should |
| 43 /// ensure that the cycle is broken, for example, by removing superclass and | 44 /// ensure that the cycle is broken, for example, by removing superclass and |
| 44 /// implemented interfaces. | 45 /// implemented interfaces. |
| 45 void breakCycle(ClassBuilder cls); | 46 void breakCycle(ClassBuilder cls); |
| 46 | 47 |
| 47 Uri translateUri(Uri uri) => uriTranslator.translate(uri); | 48 Uri translateUri(Uri uri) => uriTranslator.translate(uri); |
| 48 | 49 |
| 49 /// Returns a reference to the constructor used for creating a compile-time | 50 /// Returns a reference to the constructor used for creating a compile-time |
| 50 /// error. The constructor is expected to accept a single argument of type | 51 /// error. The constructor is expected to accept a single argument of type |
| 51 /// String, which is the compile-time error message. | 52 /// String, which is the compile-time error message. |
| 52 Builder getCompileTimeError(Loader loader) { | 53 Builder getCompileTimeError(Loader loader) { |
| 53 if (cachedCompileTimeError != null) return cachedCompileTimeError; | 54 if (cachedCompileTimeError != null) return cachedCompileTimeError; |
| 54 return cachedCompileTimeError = | 55 return cachedCompileTimeError = |
| 55 loader.coreLibrary.getConstructor("_CompileTimeError", isPrivate: true); | 56 loader.coreLibrary.getConstructor("_CompileTimeError", isPrivate: true); |
| 56 } | 57 } |
| 58 |
| 59 /// Returns a reference to the constructor used for creating `native` |
| 60 /// annotations. The constructor is expected to accept a single argument of |
| 61 /// type String, which is the name of the native method. |
| 62 Builder getNativeAnnotation(Loader loader) { |
| 63 if (cachedNativeAnnotation != null) return cachedNativeAnnotation; |
| 64 LibraryBuilder internal = loader.read(Uri.parse("dart:_internal")); |
| 65 return cachedNativeAnnotation = internal.getConstructor("ExternalName"); |
| 66 } |
| 57 } | 67 } |
| OLD | NEW |