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

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

Issue 2695633002: Annotate native methods. (Closed)
Patch Set: Created 3 years, 10 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
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.kernel_procedure_builder; 5 library fasta.kernel_procedure_builder;
6 6
7 import 'package:kernel/ast.dart' show 7 import 'package:kernel/ast.dart' show
8 Arguments, 8 Arguments,
9 AsyncMarker, 9 AsyncMarker,
10 Constructor, 10 Constructor,
11 ConstructorInvocation,
11 DartType, 12 DartType,
12 DynamicType, 13 DynamicType,
13 EmptyStatement, 14 EmptyStatement,
14 Expression, 15 Expression,
15 FunctionNode, 16 FunctionNode,
16 Initializer, 17 Initializer,
17 Library, 18 Library,
18 LocalInitializer, 19 LocalInitializer,
19 Member, 20 Member,
20 Name, 21 Name,
21 NamedExpression, 22 NamedExpression,
22 Procedure, 23 Procedure,
23 ProcedureKind, 24 ProcedureKind,
24 RedirectingInitializer, 25 RedirectingInitializer,
25 Statement, 26 Statement,
27 StaticInvocation,
28 StringLiteral,
26 SuperInitializer, 29 SuperInitializer,
27 TypeParameter, 30 TypeParameter,
28 VariableDeclaration, 31 VariableDeclaration,
29 VariableGet, 32 VariableGet,
30 VoidType, 33 VoidType,
31 setParents; 34 setParents;
32 35
33 import 'package:kernel/type_algebra.dart' show 36 import 'package:kernel/type_algebra.dart' show
34 containsTypeVariable, 37 containsTypeVariable,
35 substitute; 38 substitute;
36 39
37 import '../errors.dart' show 40 import '../errors.dart' show
38 internalError; 41 internalError;
39 42
43 import '../loader.dart' show
44 Loader;
40 45
41 import '../util/relativize.dart' show 46 import '../util/relativize.dart' show
42 relativizeUri; 47 relativizeUri;
43 48
44 import 'kernel_builder.dart' show 49 import 'kernel_builder.dart' show
50 Builder,
45 ClassBuilder, 51 ClassBuilder,
46 ConstructorReferenceBuilder, 52 ConstructorReferenceBuilder,
47 FormalParameterBuilder, 53 FormalParameterBuilder,
48 KernelFormalParameterBuilder, 54 KernelFormalParameterBuilder,
49 KernelLibraryBuilder, 55 KernelLibraryBuilder,
50 KernelTypeBuilder, 56 KernelTypeBuilder,
51 KernelTypeVariableBuilder, 57 KernelTypeVariableBuilder,
52 MetadataBuilder, 58 MetadataBuilder,
53 ProcedureBuilder, 59 ProcedureBuilder,
54 TypeVariableBuilder, 60 TypeVariableBuilder,
55 memberError; 61 memberError;
56 62
57 abstract class KernelFunctionBuilder 63 abstract class KernelFunctionBuilder
58 extends ProcedureBuilder<KernelTypeBuilder> { 64 extends ProcedureBuilder<KernelTypeBuilder> {
65 final String nativeMethodName;
66
59 FunctionNode function; 67 FunctionNode function;
60 68
61 Statement actualBody; 69 Statement actualBody;
62 70
63 KernelFunctionBuilder( 71 KernelFunctionBuilder(List<MetadataBuilder> metadata, int modifiers,
64 List<MetadataBuilder> metadata, 72 KernelTypeBuilder returnType, String name,
65 int modifiers, KernelTypeBuilder returnType, String name,
66 List<TypeVariableBuilder> typeVariables, 73 List<TypeVariableBuilder> typeVariables,
67 List<FormalParameterBuilder> formals, 74 List<FormalParameterBuilder> formals,
68 KernelLibraryBuilder compilationUnit, int charOffset) 75 KernelLibraryBuilder compilationUnit, int charOffset,
76 this.nativeMethodName)
69 : super(metadata, modifiers, returnType, name, typeVariables, formals, 77 : super(metadata, modifiers, returnType, name, typeVariables, formals,
70 compilationUnit, charOffset); 78 compilationUnit, charOffset);
71 79
72 void set body(Statement newBody) { 80 void set body(Statement newBody) {
73 if (isAbstract && newBody != null) { 81 if (isAbstract && newBody != null) {
74 return internalError("Attempting to set body on abstract method."); 82 return internalError("Attempting to set body on abstract method.");
75 } 83 }
76 actualBody = newBody; 84 actualBody = newBody;
77 if (function != null) { 85 if (function != null) {
78 function.body = newBody; 86 function.body = newBody;
79 newBody?.parent = function; 87 newBody?.parent = function;
80 } 88 }
81 } 89 }
82 90
83 Statement get body => actualBody ??= new EmptyStatement(); 91 Statement get body => actualBody ??= new EmptyStatement();
84 92
93 bool get isNative => nativeMethodName != null;
94
85 FunctionNode buildFunction() { 95 FunctionNode buildFunction() {
86 assert(function == null); 96 assert(function == null);
87 FunctionNode result = new FunctionNode(body, asyncMarker: asyncModifier); 97 FunctionNode result = new FunctionNode(body, asyncMarker: asyncModifier);
88 if (typeVariables != null) { 98 if (typeVariables != null) {
89 for (KernelTypeVariableBuilder t in typeVariables) { 99 for (KernelTypeVariableBuilder t in typeVariables) {
90 result.typeParameters.add(t.parameter); 100 result.typeParameters.add(t.parameter);
91 } 101 }
92 setParents(result.typeParameters, result); 102 setParents(result.typeParameters, result);
93 } 103 }
94 if (formals != null) { 104 if (formals != null) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 145 }
136 if (containsTypeVariable(result.returnType, set)) { 146 if (containsTypeVariable(result.returnType, set)) {
137 result.returnType = removeTypeVariables(result.returnType); 147 result.returnType = removeTypeVariables(result.returnType);
138 } 148 }
139 } 149 }
140 } 150 }
141 return function = result; 151 return function = result;
142 } 152 }
143 153
144 Member build(Library library); 154 Member build(Library library);
155
156 void becomeNative(Loader loader) {
157 target.isExternal = true;
158 Builder constructor = loader.getNativeAnnotation();
159 Arguments arguments =
160 new Arguments(<Expression>[new StringLiteral(nativeMethodName)]);
161 Expression annotation;
162 if (constructor.isConstructor) {
163 annotation = new ConstructorInvocation(constructor.target, arguments)
164 ..isConst = true;
165 } else {
166 annotation = new StaticInvocation(constructor.target, arguments)
167 ..isConst = true;
168 }
169 target.addAnnotation(annotation);
170 }
145 } 171 }
146 172
147 class KernelProcedureBuilder extends KernelFunctionBuilder { 173 class KernelProcedureBuilder extends KernelFunctionBuilder {
148 final Procedure procedure; 174 final Procedure procedure;
149 175
150 AsyncMarker actualAsyncModifier; 176 AsyncMarker actualAsyncModifier;
151 177
152 final ConstructorReferenceBuilder redirectionTarget; 178 final ConstructorReferenceBuilder redirectionTarget;
153 179
154 KernelProcedureBuilder( 180 KernelProcedureBuilder(
155 List<MetadataBuilder> metadata, 181 List<MetadataBuilder> metadata,
156 int modifiers, KernelTypeBuilder returnType, String name, 182 int modifiers, KernelTypeBuilder returnType, String name,
157 List<TypeVariableBuilder> typeVariables, 183 List<TypeVariableBuilder> typeVariables,
158 List<FormalParameterBuilder> formals, this.actualAsyncModifier, 184 List<FormalParameterBuilder> formals, this.actualAsyncModifier,
159 ProcedureKind kind, KernelLibraryBuilder compilationUnit, int charOffset, 185 ProcedureKind kind, KernelLibraryBuilder compilationUnit, int charOffset,
160 [this.redirectionTarget]) 186 [String nativeMethodName, this.redirectionTarget])
161 : procedure = new Procedure(null, kind, null, 187 : procedure = new Procedure(null, kind, null,
162 fileUri: relativizeUri(compilationUnit?.fileUri)), 188 fileUri: relativizeUri(compilationUnit?.fileUri)),
163 super(metadata, modifiers, returnType, name, typeVariables, formals, 189 super(metadata, modifiers, returnType, name, typeVariables, formals,
164 compilationUnit, charOffset); 190 compilationUnit, charOffset, nativeMethodName);
165 191
166 ProcedureKind get kind => procedure.kind; 192 ProcedureKind get kind => procedure.kind;
167 193
168 AsyncMarker get asyncModifier => actualAsyncModifier; 194 AsyncMarker get asyncModifier => actualAsyncModifier;
169 195
170 Statement get body { 196 Statement get body {
171 if (actualBody == null && redirectionTarget == null && !isAbstract && 197 if (actualBody == null && redirectionTarget == null && !isAbstract &&
172 !isExternal) { 198 !isExternal) {
173 actualBody = new EmptyStatement(); 199 actualBody = new EmptyStatement();
174 } 200 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 234
209 SuperInitializer superInitializer; 235 SuperInitializer superInitializer;
210 236
211 RedirectingInitializer redirectingInitializer; 237 RedirectingInitializer redirectingInitializer;
212 238
213 KernelConstructorBuilder( 239 KernelConstructorBuilder(
214 List<MetadataBuilder> metadata, 240 List<MetadataBuilder> metadata,
215 int modifiers, KernelTypeBuilder returnType, String name, 241 int modifiers, KernelTypeBuilder returnType, String name,
216 List<TypeVariableBuilder> typeVariables, 242 List<TypeVariableBuilder> typeVariables,
217 List<FormalParameterBuilder> formals, 243 List<FormalParameterBuilder> formals,
218 KernelLibraryBuilder compilationUnit, int charOffset) 244 KernelLibraryBuilder compilationUnit, int charOffset,
245 [String nativeMethodName])
219 : super(metadata, modifiers, returnType, name, typeVariables, formals, 246 : super(metadata, modifiers, returnType, name, typeVariables, formals,
220 compilationUnit, charOffset); 247 compilationUnit, charOffset, nativeMethodName);
221 248
222 bool get isInstanceMember => false; 249 bool get isInstanceMember => false;
223 250
224 bool get isConstructor => true; 251 bool get isConstructor => true;
225 252
226 AsyncMarker get asyncModifier => AsyncMarker.Sync; 253 AsyncMarker get asyncModifier => AsyncMarker.Sync;
227 254
228 ProcedureKind get kind => null; 255 ProcedureKind get kind => null;
229 256
230 Constructor build(Library library) { 257 Constructor build(Library library) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 327 }
301 } 328 }
302 initializers.add(initializer..parent = constructor); 329 initializers.add(initializer..parent = constructor);
303 initializers.add(superInitializer); 330 initializers.add(superInitializer);
304 return; 331 return;
305 } 332 }
306 initializers.add(initializer); 333 initializers.add(initializer);
307 initializer.parent = constructor; 334 initializer.parent = constructor;
308 } 335 }
309 } 336 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart ('k') | pkg/front_end/lib/src/fasta/kernel/kernel_target.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698