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 'package:kernel/target/targets.dart' as backend show Target; | 7 import 'package:kernel/target/targets.dart' as backend show Target; |
8 | 8 |
9 import 'package:kernel/ast.dart' show Arguments, Expression, Member; | |
10 | |
11 import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; | 9 import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; |
12 | 10 |
13 import 'parser/dart_vm_native.dart' as vm show skipNativeClause; | 11 import 'parser/dart_vm_native.dart' as vm show skipNativeClause; |
14 | 12 |
15 import '../scanner/token.dart' show Token; | 13 import '../scanner/token.dart' show Token; |
16 | 14 |
17 import 'loader.dart' show Loader; | 15 import 'loader.dart' show Loader; |
18 | 16 |
19 import 'quote.dart' show unescapeString; | 17 import 'quote.dart' show unescapeString; |
20 | 18 |
21 import 'target.dart' show Target; | 19 import 'target.dart' show Target; |
22 | 20 |
23 import 'ticker.dart' show Ticker; | 21 import 'ticker.dart' show Ticker; |
24 | 22 |
25 import 'translate_uri.dart' show TranslateUri; | 23 import 'translate_uri.dart' show TranslateUri; |
26 | 24 |
27 /// Provides the implementation details used by a loader for a target. | 25 /// Provides the implementation details used by a loader for a target. |
28 abstract class TargetImplementation extends Target { | 26 abstract class TargetImplementation extends Target { |
29 final TranslateUri uriTranslator; | 27 final TranslateUri uriTranslator; |
30 | 28 |
31 final backend.Target backendTarget; | 29 final backend.Target backendTarget; |
32 | 30 |
33 Builder cachedAbstractClassInstantiationError; | 31 Builder cachedAbstractClassInstantiationError; |
34 Builder cachedCompileTimeError; | 32 Builder cachedCompileTimeError; |
35 Builder cachedDuplicatedFieldInitializerError; | 33 Builder cachedDuplicatedFieldInitializerError; |
36 Builder cachedFallThroughError; | 34 Builder cachedFallThroughError; |
37 Builder cachedInvocation; | |
38 Builder cachedNativeAnnotation; | 35 Builder cachedNativeAnnotation; |
39 Builder cachedNoSuchMethodError; | |
40 | 36 |
41 TargetImplementation(Ticker ticker, this.uriTranslator, this.backendTarget) | 37 TargetImplementation(Ticker ticker, this.uriTranslator, this.backendTarget) |
42 : super(ticker); | 38 : super(ticker); |
43 | 39 |
44 /// Creates a [LibraryBuilder] corresponding to [uri], if one doesn't exist | 40 /// Creates a [LibraryBuilder] corresponding to [uri], if one doesn't exist |
45 /// already. | 41 /// already. |
46 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri, bool isPatch); | 42 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri, bool isPatch); |
47 | 43 |
48 /// Add the classes extended or implemented directly by [cls] to [set]. | 44 /// Add the classes extended or implemented directly by [cls] to [set]. |
49 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set); | 45 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 /// Returns a reference to the constructor of [FallThroughError] error. The | 90 /// Returns a reference to the constructor of [FallThroughError] error. The |
95 /// constructor is expected to accept no arguments. | 91 /// constructor is expected to accept no arguments. |
96 Builder getFallThroughError(Loader loader) { | 92 Builder getFallThroughError(Loader loader) { |
97 if (cachedFallThroughError != null) { | 93 if (cachedFallThroughError != null) { |
98 return cachedFallThroughError; | 94 return cachedFallThroughError; |
99 } | 95 } |
100 return cachedFallThroughError = | 96 return cachedFallThroughError = |
101 loader.coreLibrary.getConstructor("FallThroughError"); | 97 loader.coreLibrary.getConstructor("FallThroughError"); |
102 } | 98 } |
103 | 99 |
104 /// Returns a reference to the constructor of [Invocation]. The | |
105 /// constructor is expected to accept these arguments: | |
106 /// | |
107 /// String functionName, | |
108 /// List argumentsDescriptor, | |
109 /// List arguments, | |
110 /// bool isSuperInvocation | |
111 Builder getInvocation(Loader loader) { | |
112 if (cachedInvocation != null) { | |
113 return cachedInvocation; | |
114 } | |
115 return cachedInvocation = loader.coreLibrary | |
116 .getConstructor("_InvocationMirror", bypassLibraryPrivacy: true); | |
117 } | |
118 | |
119 /// Returns a reference to the constructor used for creating `native` | 100 /// Returns a reference to the constructor used for creating `native` |
120 /// annotations. The constructor is expected to accept a single argument of | 101 /// annotations. The constructor is expected to accept a single argument of |
121 /// type String, which is the name of the native method. | 102 /// type String, which is the name of the native method. |
122 Builder getNativeAnnotation(Loader loader) { | 103 Builder getNativeAnnotation(Loader loader) { |
123 if (cachedNativeAnnotation != null) return cachedNativeAnnotation; | 104 if (cachedNativeAnnotation != null) return cachedNativeAnnotation; |
124 LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1); | 105 LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1); |
125 return cachedNativeAnnotation = internal.getConstructor("ExternalName"); | 106 return cachedNativeAnnotation = internal.getConstructor("ExternalName"); |
126 } | 107 } |
127 | 108 |
128 /// Returns a reference to the constructor of [NoSuchMethodError] error. The | |
129 /// constructor is expected to accept these arguments: | |
130 /// | |
131 /// Object receiver, // A class literal for static methods. | |
132 /// Symbol memberName, | |
133 /// int type, // [computeNoSuchMethodType](kernel/kernel_builder.dart). | |
134 /// List positionalArguments, | |
135 /// Map<Symbol, dynamic> namedArguments, | |
136 Builder getNoSuchMethodError(Loader loader) { | |
137 if (cachedNoSuchMethodError != null) { | |
138 return cachedNoSuchMethodError; | |
139 } | |
140 return cachedNoSuchMethodError = loader.coreLibrary | |
141 .getConstructor("NoSuchMethodError", constructorName: "_withType"); | |
142 } | |
143 | |
144 void loadExtraRequiredLibraries(Loader loader) { | 109 void loadExtraRequiredLibraries(Loader loader) { |
145 for (String uri in backendTarget.extraRequiredLibraries) { | 110 for (String uri in backendTarget.extraRequiredLibraries) { |
146 loader.read(Uri.parse(uri), -1); | 111 loader.read(Uri.parse(uri), -1); |
147 } | 112 } |
148 } | 113 } |
149 | 114 |
150 /// Whether the `native` language extension is supported within [library]. | 115 /// Whether the `native` language extension is supported within [library]. |
151 /// | 116 /// |
152 /// The `native` language extension is not part of the language specification, | 117 /// The `native` language extension is not part of the language specification, |
153 /// means something else to each target, and is enabled differently for each | 118 /// means something else to each target, and is enabled differently for each |
(...skipping 17 matching lines...) Expand all Loading... |
171 | 136 |
172 void readPatchFiles(LibraryBuilder library) { | 137 void readPatchFiles(LibraryBuilder library) { |
173 assert(library.uri.scheme == "dart"); | 138 assert(library.uri.scheme == "dart"); |
174 List<Uri> patches = uriTranslator.patches[library.uri.path]; | 139 List<Uri> patches = uriTranslator.patches[library.uri.path]; |
175 if (patches != null) { | 140 if (patches != null) { |
176 for (Uri patch in patches) { | 141 for (Uri patch in patches) { |
177 library.loader.read(patch, -1, fileUri: patch, isPatch: true); | 142 library.loader.read(patch, -1, fileUri: patch, isPatch: true); |
178 } | 143 } |
179 } | 144 } |
180 } | 145 } |
181 | |
182 Expression instantiateInvocation(Member target, Expression receiver, | |
183 String name, Arguments arguments, int offset, bool isSuper) { | |
184 return backendTarget.instantiateInvocation( | |
185 target, receiver, name, arguments, offset, isSuper); | |
186 } | |
187 } | 146 } |
OLD | NEW |