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

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

Issue 2691523002: Ensure locations are always provided, but don't store them yet. (Closed)
Patch Set: Missing file. 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,
(...skipping 22 matching lines...) Expand all
33 import 'package:kernel/type_algebra.dart' show 33 import 'package:kernel/type_algebra.dart' show
34 containsTypeVariable, 34 containsTypeVariable,
35 substitute; 35 substitute;
36 36
37 import '../errors.dart' show 37 import '../errors.dart' show
38 internalError; 38 internalError;
39 39
40 import '../modifier.dart' show 40 import '../modifier.dart' show
41 abstractMask; 41 abstractMask;
42 42
43 import '../util/relativize.dart' show
44 relativizeUri;
45
43 import 'kernel_builder.dart' show 46 import 'kernel_builder.dart' show
44 ClassBuilder, 47 ClassBuilder,
45 ConstructorReferenceBuilder, 48 ConstructorReferenceBuilder,
46 FormalParameterBuilder, 49 FormalParameterBuilder,
47 KernelFormalParameterBuilder, 50 KernelFormalParameterBuilder,
51 KernelLibraryBuilder,
48 KernelTypeBuilder, 52 KernelTypeBuilder,
49 KernelTypeVariableBuilder, 53 KernelTypeVariableBuilder,
50 MetadataBuilder, 54 MetadataBuilder,
51 ProcedureBuilder, 55 ProcedureBuilder,
52 TypeBuilder, 56 TypeBuilder,
53 TypeVariableBuilder, 57 TypeVariableBuilder,
54 memberError; 58 memberError;
55 59
56 abstract class KernelFunctionBuilder 60 abstract class KernelFunctionBuilder
57 extends ProcedureBuilder<KernelTypeBuilder> { 61 extends ProcedureBuilder<KernelTypeBuilder> {
58 FunctionNode function; 62 FunctionNode function;
59 63
60 Statement actualBody; 64 Statement actualBody;
61 65
62 KernelFunctionBuilder( 66 KernelFunctionBuilder(
63 List<MetadataBuilder> metadata, 67 List<MetadataBuilder> metadata,
64 int modifiers, KernelTypeBuilder returnType, String name, 68 int modifiers, KernelTypeBuilder returnType, String name,
65 List<TypeVariableBuilder> typeVariables, 69 List<TypeVariableBuilder> typeVariables,
66 List<FormalParameterBuilder> formals) 70 List<FormalParameterBuilder> formals,
67 : super(metadata, modifiers, returnType, name, typeVariables, formals); 71 KernelLibraryBuilder compilationUnit, int charOffset)
72 : super(metadata, modifiers, returnType, name, typeVariables, formals,
73 compilationUnit, charOffset);
68 74
69 void set body(Statement newBody) { 75 void set body(Statement newBody) {
70 if (isAbstract && newBody != null) { 76 if (isAbstract && newBody != null) {
71 return internalError("Attempting to set body on abstract method."); 77 return internalError("Attempting to set body on abstract method.");
72 } 78 }
73 actualBody = newBody; 79 actualBody = newBody;
74 if (function != null) { 80 if (function != null) {
75 function.body = newBody; 81 function.body = newBody;
76 newBody?.parent = function; 82 newBody?.parent = function;
77 } 83 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 152
147 AsyncMarker actualAsyncModifier; 153 AsyncMarker actualAsyncModifier;
148 154
149 final ConstructorReferenceBuilder redirectionTarget; 155 final ConstructorReferenceBuilder redirectionTarget;
150 156
151 KernelProcedureBuilder( 157 KernelProcedureBuilder(
152 List<MetadataBuilder> metadata, 158 List<MetadataBuilder> metadata,
153 int modifiers, KernelTypeBuilder returnType, String name, 159 int modifiers, KernelTypeBuilder returnType, String name,
154 List<TypeVariableBuilder> typeVariables, 160 List<TypeVariableBuilder> typeVariables,
155 List<FormalParameterBuilder> formals, this.actualAsyncModifier, 161 List<FormalParameterBuilder> formals, this.actualAsyncModifier,
156 ProcedureKind kind, [this.redirectionTarget]) 162 ProcedureKind kind, KernelLibraryBuilder compilationUnit, int charOffset,
157 : procedure = new Procedure(null, kind, null), 163 [this.redirectionTarget])
158 super(metadata, modifiers, returnType, name, typeVariables, formals); 164 : procedure = new Procedure(null, kind, null,
165 fileUri: relativizeUri(compilationUnit?.fileUri)),
166 super(metadata, modifiers, returnType, name, typeVariables, formals,
167 compilationUnit, charOffset);
159 168
160 ProcedureKind get kind => procedure.kind; 169 ProcedureKind get kind => procedure.kind;
161 170
162 AsyncMarker get asyncModifier => actualAsyncModifier; 171 AsyncMarker get asyncModifier => actualAsyncModifier;
163 172
164 Statement get body { 173 Statement get body {
165 if (actualBody == null && redirectionTarget == null && !isAbstract && 174 if (actualBody == null && redirectionTarget == null && !isAbstract &&
166 !isExternal) { 175 !isExternal) {
167 actualBody = new EmptyStatement(); 176 actualBody = new EmptyStatement();
168 } 177 }
(...skipping 29 matching lines...) Expand all
198 if (isFactory) { 207 if (isFactory) {
199 if (this.typeVariables != null) { 208 if (this.typeVariables != null) {
200 return memberError(target, "Factories can't be generic."); 209 return memberError(target, "Factories can't be generic.");
201 } 210 }
202 List<KernelTypeVariableBuilder> typeVariables; 211 List<KernelTypeVariableBuilder> typeVariables;
203 KernelTypeBuilder returnType = this.returnType; 212 KernelTypeBuilder returnType = this.returnType;
204 List<FormalParameterBuilder> formals; 213 List<FormalParameterBuilder> formals;
205 if (classTypeVariables != null) { 214 if (classTypeVariables != null) {
206 typeVariables = <KernelTypeVariableBuilder>[]; 215 typeVariables = <KernelTypeVariableBuilder>[];
207 for (KernelTypeVariableBuilder variable in classTypeVariables) { 216 for (KernelTypeVariableBuilder variable in classTypeVariables) {
208 typeVariables.add(new KernelTypeVariableBuilder(variable.name)); 217 typeVariables.add(new KernelTypeVariableBuilder(
218 variable.name, null, -1));
209 } 219 }
210 Map<TypeVariableBuilder, TypeBuilder> substitution = 220 Map<TypeVariableBuilder, TypeBuilder> substitution =
211 <TypeVariableBuilder, TypeBuilder>{}; 221 <TypeVariableBuilder, TypeBuilder>{};
212 int i = 0; 222 int i = 0;
213 for (KernelTypeVariableBuilder variable in classTypeVariables) { 223 for (KernelTypeVariableBuilder variable in classTypeVariables) {
214 substitution[variable] = typeVariables[i++].asTypeBuilder(); 224 substitution[variable] = typeVariables[i++].asTypeBuilder();
215 } 225 }
216 i = 0; 226 i = 0;
217 for (KernelTypeVariableBuilder variable in classTypeVariables) { 227 for (KernelTypeVariableBuilder variable in classTypeVariables) {
218 typeVariables[i++].bound = variable?.bound?.subst(substitution); 228 typeVariables[i++].bound = variable?.bound?.subst(substitution);
219 } 229 }
220 returnType = returnType?.subst(substitution); 230 returnType = returnType?.subst(substitution);
221 i = 0; 231 i = 0;
222 if (this.formals != null) { 232 if (this.formals != null) {
223 for (KernelFormalParameterBuilder formal in this.formals) { 233 for (KernelFormalParameterBuilder formal in this.formals) {
224 KernelTypeBuilder type = formal.type?.subst(substitution); 234 KernelTypeBuilder type = formal.type?.subst(substitution);
225 if (type != formal.type) { 235 if (type != formal.type) {
226 formals ??= this.formals.toList(); 236 formals ??= this.formals.toList();
227 formals[i] = new KernelFormalParameterBuilder(formal.metadata, 237 formals[i] = new KernelFormalParameterBuilder(formal.metadata,
228 formal.modifiers, type, formal.name, formal.hasThis); 238 formal.modifiers, type, formal.name, formal.hasThis, null,
239 -1);
229 } 240 }
230 i++; 241 i++;
231 } 242 }
232 } 243 }
233 } 244 }
234 formals ??= this.formals; 245 formals ??= this.formals;
235 return new KernelProcedureBuilder( 246 KernelProcedureBuilder factory = new KernelProcedureBuilder(
236 metadata, modifiers, returnType, name, typeVariables, formals, 247 metadata, modifiers, returnType, name, typeVariables, formals,
237 actualAsyncModifier, kind, redirectionTarget) 248 actualAsyncModifier, kind, null, -1, redirectionTarget)
238 ..parent = parent; 249 ..parent = parent;
250 factory.procedure.fileUri = procedure.fileUri;
251 return factory;
239 } else { 252 } else {
240 return new KernelConstructorBuilder(metadata, modifiers & ~abstractMask, 253 return new KernelConstructorBuilder(metadata, modifiers & ~abstractMask,
241 returnType, name, typeVariables, formals) 254 returnType, name, typeVariables, formals, null, -1)
Johnni Winther 2017/02/13 08:42:03 Set [fileUri] on this?
ahe 2017/02/13 10:44:23 This code is removed by CL 2682333004.
242 ..parent = parent; 255 ..parent = parent;
243 } 256 }
244 } 257 }
245 258
246 Procedure get target => procedure; 259 Procedure get target => procedure;
247 } 260 }
248 261
249 // TODO(ahe): Move this to own file? 262 // TODO(ahe): Move this to own file?
250 class KernelConstructorBuilder extends KernelFunctionBuilder { 263 class KernelConstructorBuilder extends KernelFunctionBuilder {
251 final Constructor constructor = new Constructor(null); 264 final Constructor constructor = new Constructor(null);
252 265
253 bool hasMovedSuperInitializer = false; 266 bool hasMovedSuperInitializer = false;
254 267
255 SuperInitializer superInitializer; 268 SuperInitializer superInitializer;
256 269
257 RedirectingInitializer redirectingInitializer; 270 RedirectingInitializer redirectingInitializer;
258 271
259 KernelConstructorBuilder( 272 KernelConstructorBuilder(
260 List<MetadataBuilder> metadata, 273 List<MetadataBuilder> metadata,
261 int modifiers, KernelTypeBuilder returnType, String name, 274 int modifiers, KernelTypeBuilder returnType, String name,
262 List<TypeVariableBuilder> typeVariables, 275 List<TypeVariableBuilder> typeVariables,
263 List<FormalParameterBuilder> formals) 276 List<FormalParameterBuilder> formals,
264 : super(metadata, modifiers, returnType, name, typeVariables, formals); 277 KernelLibraryBuilder compilationUnit, int charOffset)
278 : super(metadata, modifiers, returnType, name, typeVariables, formals,
279 compilationUnit, charOffset);
265 280
266 bool get isInstanceMember => false; 281 bool get isInstanceMember => false;
267 282
268 bool get isConstructor => true; 283 bool get isConstructor => true;
269 284
270 AsyncMarker get asyncModifier => AsyncMarker.Sync; 285 AsyncMarker get asyncModifier => AsyncMarker.Sync;
271 286
272 ProcedureKind get kind => null; 287 ProcedureKind get kind => null;
273 288
274 Constructor build(Library library) { 289 Constructor build(Library library) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 359 }
345 } 360 }
346 initializers.add(initializer..parent = constructor); 361 initializers.add(initializer..parent = constructor);
347 initializers.add(superInitializer); 362 initializers.add(superInitializer);
348 return; 363 return;
349 } 364 }
350 initializers.add(initializer); 365 initializers.add(initializer);
351 initializer.parent = constructor; 366 initializer.parent = constructor;
352 } 367 }
353 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698