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

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

Issue 2917863003: Various infrastructure changes. (Closed)
Patch Set: Fix comment. Created 3 years, 6 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
« no previous file with comments | « pkg/front_end/lib/src/fasta/loader.dart ('k') | runtime/lib/errors_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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
9 import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; 11 import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder;
10 12
11 import 'parser/dart_vm_native.dart' as vm show skipNativeClause; 13 import 'parser/dart_vm_native.dart' as vm show skipNativeClause;
12 14
13 import '../scanner/token.dart' show Token; 15 import '../scanner/token.dart' show Token;
14 16
15 import 'loader.dart' show Loader; 17 import 'loader.dart' show Loader;
16 18
17 import 'quote.dart' show unescapeString; 19 import 'quote.dart' show unescapeString;
18 20
19 import 'target.dart' show Target; 21 import 'target.dart' show Target;
20 22
21 import 'ticker.dart' show Ticker; 23 import 'ticker.dart' show Ticker;
22 24
23 import 'translate_uri.dart' show TranslateUri; 25 import 'translate_uri.dart' show TranslateUri;
24 26
25 /// Provides the implementation details used by a loader for a target. 27 /// Provides the implementation details used by a loader for a target.
26 abstract class TargetImplementation extends Target { 28 abstract class TargetImplementation extends Target {
27 final TranslateUri uriTranslator; 29 final TranslateUri uriTranslator;
28 30
29 final backend.Target backendTarget; 31 final backend.Target backendTarget;
30 32
33 Builder cachedAbstractClassInstantiationError;
31 Builder cachedCompileTimeError; 34 Builder cachedCompileTimeError;
32 Builder cachedAbstractClassInstantiationError; 35 Builder cachedDuplicatedFieldInitializerError;
36 Builder cachedFallThroughError;
37 Builder cachedInvocation;
33 Builder cachedNativeAnnotation; 38 Builder cachedNativeAnnotation;
39 Builder cachedNoSuchMethodError;
34 40
35 TargetImplementation(Ticker ticker, this.uriTranslator, this.backendTarget) 41 TargetImplementation(Ticker ticker, this.uriTranslator, this.backendTarget)
36 : super(ticker); 42 : super(ticker);
37 43
38 /// Creates a [LibraryBuilder] corresponding to [uri], if one doesn't exist 44 /// Creates a [LibraryBuilder] corresponding to [uri], if one doesn't exist
39 /// already. 45 /// already.
40 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri, bool isPatch); 46 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri, bool isPatch);
41 47
42 /// Add the classes extended or implemented directly by [cls] to [set]. 48 /// Add the classes extended or implemented directly by [cls] to [set].
43 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set); 49 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set);
44 50
45 /// Returns all classes that will be included in the resulting program. 51 /// Returns all classes that will be included in the resulting program.
46 List<ClassBuilder> collectAllClasses(); 52 List<ClassBuilder> collectAllClasses();
47 53
48 /// The class [cls] is involved in a cyclic definition. This method should 54 /// The class [cls] is involved in a cyclic definition. This method should
49 /// ensure that the cycle is broken, for example, by removing superclass and 55 /// ensure that the cycle is broken, for example, by removing superclass and
50 /// implemented interfaces. 56 /// implemented interfaces.
51 void breakCycle(ClassBuilder cls); 57 void breakCycle(ClassBuilder cls);
52 58
53 Uri translateUri(Uri uri) => uriTranslator.translate(uri); 59 Uri translateUri(Uri uri) => uriTranslator.translate(uri);
54 60
55 /// Returns a reference to the constructor used for creating a compile-time
56 /// error. The constructor is expected to accept a single argument of type
57 /// String, which is the compile-time error message.
58 Builder getCompileTimeError(Loader loader) {
59 if (cachedCompileTimeError != null) return cachedCompileTimeError;
60 return cachedCompileTimeError =
61 loader.coreLibrary.getConstructor("_CompileTimeError", isPrivate: true);
62 }
63
64 /// Returns a reference to the constructor of 61 /// Returns a reference to the constructor of
65 /// [AbstractClassInstantiationError] error. The constructor is expected to 62 /// [AbstractClassInstantiationError] error. The constructor is expected to
66 /// accept a single argument of type String, which is the name of the 63 /// accept a single argument of type String, which is the name of the
67 /// abstract class. 64 /// abstract class.
68 Builder getAbstractClassInstantiationError(Loader loader) { 65 Builder getAbstractClassInstantiationError(Loader loader) {
69 if (cachedAbstractClassInstantiationError != null) { 66 if (cachedAbstractClassInstantiationError != null) {
70 return cachedAbstractClassInstantiationError; 67 return cachedAbstractClassInstantiationError;
71 } 68 }
72 return cachedAbstractClassInstantiationError = 69 return cachedAbstractClassInstantiationError =
73 loader.coreLibrary.getConstructor("AbstractClassInstantiationError"); 70 loader.coreLibrary.getConstructor("AbstractClassInstantiationError");
74 } 71 }
75 72
73 /// Returns a reference to the constructor used for creating a compile-time
74 /// error. The constructor is expected to accept a single argument of type
75 /// String, which is the compile-time error message.
76 Builder getCompileTimeError(Loader loader) {
77 if (cachedCompileTimeError != null) return cachedCompileTimeError;
78 return cachedCompileTimeError =
79 loader.coreLibrary.getConstructor("_CompileTimeError", isPrivate: true);
80 }
81
82 /// Returns a reference to the constructor used for creating a runtime error
83 /// when a final field is initialized twice. The constructor is expected to
84 /// accept a single argument which is the name of the field.
85 Builder getDuplicatedFieldInitializerError(Loader loader) {
86 if (cachedDuplicatedFieldInitializerError != null) {
87 return cachedDuplicatedFieldInitializerError;
88 }
89 return cachedDuplicatedFieldInitializerError = loader.coreLibrary
90 .getConstructor("_DuplicatedFieldInitializerError", isPrivate: true);
91 }
92
93 /// Returns a reference to the constructor of [FallThroughError] error. The
94 /// constructor is expected to accept no arguments.
95 Builder getFallThroughError(Loader loader) {
96 if (cachedFallThroughError != null) {
97 return cachedFallThroughError;
98 }
99 return cachedFallThroughError =
100 loader.coreLibrary.getConstructor("FallThroughError");
101 }
102
103 /// Returns a reference to the constructor of [Invocation]. The
104 /// constructor is expected to accept these arguments:
105 ///
106 /// String functionName,
107 /// List argumentsDescriptor,
108 /// List arguments,
109 /// bool isSuperInvocation
110 Builder getInvocation(Loader loader) {
111 if (cachedInvocation != null) {
112 return cachedInvocation;
113 }
114 return cachedInvocation =
115 loader.coreLibrary.getConstructor("_InvocationMirror", isPrivate: true);
116 }
117
76 /// Returns a reference to the constructor used for creating `native` 118 /// Returns a reference to the constructor used for creating `native`
77 /// annotations. The constructor is expected to accept a single argument of 119 /// annotations. The constructor is expected to accept a single argument of
78 /// type String, which is the name of the native method. 120 /// type String, which is the name of the native method.
79 Builder getNativeAnnotation(Loader loader) { 121 Builder getNativeAnnotation(Loader loader) {
80 if (cachedNativeAnnotation != null) return cachedNativeAnnotation; 122 if (cachedNativeAnnotation != null) return cachedNativeAnnotation;
81 LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1); 123 LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1);
82 return cachedNativeAnnotation = internal.getConstructor("ExternalName"); 124 return cachedNativeAnnotation = internal.getConstructor("ExternalName");
83 } 125 }
84 126
127 /// Returns a reference to the constructor of [NoSuchMethodError] error. The
128 /// constructor is expected to accept these arguments:
129 ///
130 /// Object receiver, // A class literal for static methods.
131 /// Symbol memberName,
132 /// int type, // [computeNoSuchMethodType](kernel/kernel_builder.dart).
133 /// List positionalArguments,
134 /// Map<Symbol, dynamic> namedArguments,
135 Builder getNoSuchMethodError(Loader loader) {
136 if (cachedNoSuchMethodError != null) {
137 return cachedNoSuchMethodError;
138 }
139 return cachedNoSuchMethodError = loader.coreLibrary
140 .getConstructor("NoSuchMethodError", constructorName: "_withType");
141 }
142
85 void loadExtraRequiredLibraries(Loader loader) { 143 void loadExtraRequiredLibraries(Loader loader) {
86 for (String uri in backendTarget.extraRequiredLibraries) { 144 for (String uri in backendTarget.extraRequiredLibraries) {
87 loader.read(Uri.parse(uri), -1); 145 loader.read(Uri.parse(uri), -1);
88 } 146 }
89 } 147 }
90 148
91 /// Whether the `native` language extension is supported within [library]. 149 /// Whether the `native` language extension is supported within [library].
92 /// 150 ///
93 /// The `native` language extension is not part of the language specification, 151 /// The `native` language extension is not part of the language specification,
94 /// means something else to each target, and is enabled differently for each 152 /// means something else to each target, and is enabled differently for each
(...skipping 17 matching lines...) Expand all
112 170
113 void readPatchFiles(LibraryBuilder library) { 171 void readPatchFiles(LibraryBuilder library) {
114 assert(library.uri.scheme == "dart"); 172 assert(library.uri.scheme == "dart");
115 List<Uri> patches = uriTranslator.patches[library.uri.path]; 173 List<Uri> patches = uriTranslator.patches[library.uri.path];
116 if (patches != null) { 174 if (patches != null) {
117 for (Uri patch in patches) { 175 for (Uri patch in patches) {
118 library.loader.read(patch, -1, fileUri: patch, isPatch: true); 176 library.loader.read(patch, -1, fileUri: patch, isPatch: true);
119 } 177 }
120 } 178 }
121 } 179 }
180
181 Expression instantiateInvocation(Member target, Expression receiver,
182 String name, Arguments arguments, int offset, bool isSuper) {
183 return backendTarget.instantiateInvocation(
184 target, receiver, name, arguments, offset, isSuper);
185 }
122 } 186 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/loader.dart ('k') | runtime/lib/errors_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698