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

Side by Side Diff: pkg/compiler/lib/src/kernel/kernel.dart

Issue 2574193003: Support generic methods in kernel (Closed)
Patch Set: Cleanup Created 4 years 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 | « no previous file | pkg/compiler/lib/src/kernel/kernel_visitor.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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection' show Queue; 6 import 'dart:collection' show Queue;
7 7
8 import 'package:kernel/ast.dart' as ir; 8 import 'package:kernel/ast.dart' as ir;
9 import 'package:kernel/verifier.dart' show CheckParentPointers; 9 import 'package:kernel/verifier.dart' show CheckParentPointers;
10 10
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 ir.Supertype supertypeToIr(InterfaceType type) { 296 ir.Supertype supertypeToIr(InterfaceType type) {
297 ir.Class cls = classToIr(type.element); 297 ir.Class cls = classToIr(type.element);
298 if (type.typeArguments.isEmpty) { 298 if (type.typeArguments.isEmpty) {
299 return cls.asRawSupertype; 299 return cls.asRawSupertype;
300 } else { 300 } else {
301 return new ir.Supertype(cls, typesToIr(type.typeArguments)); 301 return new ir.Supertype(cls, typesToIr(type.typeArguments));
302 } 302 }
303 } 303 }
304 304
305 // TODO(ahe): Remove this method when dart2js support generic type arguments.
306 List<ir.TypeParameter> typeParametersNotImplemented() {
307 return const <ir.TypeParameter>[];
308 }
309
310 ir.FunctionType functionTypeToIr(FunctionType type) { 305 ir.FunctionType functionTypeToIr(FunctionType type) {
311 List<ir.TypeParameter> typeParameters = typeParametersNotImplemented(); 306 List<ir.TypeParameter> typeParameters = <ir.TypeParameter>[];
312 int requiredParameterCount = type.parameterTypes.length; 307 int requiredParameterCount = type.parameterTypes.length;
313 List<ir.DartType> positionalParameters = 308 List<ir.DartType> positionalParameters =
314 new List<ir.DartType>.from(typesToIr(type.parameterTypes)) 309 new List<ir.DartType>.from(typesToIr(type.parameterTypes))
315 ..addAll(typesToIr(type.optionalParameterTypes)); 310 ..addAll(typesToIr(type.optionalParameterTypes));
316 List<ir.NamedType> namedParameters = new List<ir.NamedType>.generate( 311 List<ir.NamedType> namedParameters = new List<ir.NamedType>.generate(
317 type.namedParameters.length, 312 type.namedParameters.length,
318 (i) => new ir.NamedType( 313 (i) => new ir.NamedType(
319 type.namedParameters[i], typeToIr(type.namedParameterTypes[i]))); 314 type.namedParameters[i], typeToIr(type.namedParameterTypes[i])));
320 ir.DartType returnType = typeToIr(type.returnType); 315 ir.DartType returnType = typeToIr(type.returnType);
321 316
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 // TODO(ahe): Add setInitializers to [ir.Constructor]. 450 // TODO(ahe): Add setInitializers to [ir.Constructor].
456 for (ir.Initializer initializer in irFunction.initializers) { 451 for (ir.Initializer initializer in irFunction.initializers) {
457 initializer.parent = constructor; 452 initializer.parent = constructor;
458 } 453 }
459 } else { 454 } else {
460 assert(irFunction.kind != null); 455 assert(irFunction.kind != null);
461 procedure.function = irFunction.node; 456 procedure.function = irFunction.node;
462 procedure.kind = irFunction.kind; 457 procedure.kind = irFunction.kind;
463 } 458 }
464 endFactoryScope(function); 459 endFactoryScope(function);
460 irFunction.node.typeParameters
461 .addAll(typeVariablesToIr(function.typeVariables));
465 member.transformerFlags = visitor.transformerFlags; 462 member.transformerFlags = visitor.transformerFlags;
466 assert(() { 463 assert(() {
467 visitor.locals.forEach(checkMember); 464 visitor.locals.forEach(checkMember);
468 return true; 465 return true;
469 }); 466 });
470 }); 467 });
471 addWork(function.declaration, () { 468 addWork(function.declaration, () {
472 for (MetadataAnnotation metadata in function.declaration.metadata) { 469 for (MetadataAnnotation metadata in function.declaration.metadata) {
473 member.addAnnotation( 470 member.addAnnotation(
474 const ConstantVisitor().visit(metadata.constant, this)); 471 const ConstantVisitor().visit(metadata.constant, this));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 }); 546 });
550 } 547 }
551 548
552 ir.TypeParameter typeVariableToIr(TypeVariableElement variable) { 549 ir.TypeParameter typeVariableToIr(TypeVariableElement variable) {
553 variable = variable.declaration; 550 variable = variable.declaration;
554 ir.TypeParameter parameter = factoryTypeParameters[variable]; 551 ir.TypeParameter parameter = factoryTypeParameters[variable];
555 if (parameter != null) return parameter; 552 if (parameter != null) return parameter;
556 return typeParameters.putIfAbsent(variable, () { 553 return typeParameters.putIfAbsent(variable, () {
557 ir.TypeParameter parameter = new ir.TypeParameter(variable.name, null); 554 ir.TypeParameter parameter = new ir.TypeParameter(variable.name, null);
558 addWork(variable, () { 555 addWork(variable, () {
559 // TODO(ahe): This assignment will probably not be correct when dart2js 556 if (variable.typeDeclaration.isClass) {
560 // supports generic methods. 557 ClassElement cls = variable.typeDeclaration;
561 ClassElement cls = variable.typeDeclaration; 558 cls.ensureResolved(compiler.resolution);
562 cls.ensureResolved(compiler.resolution); 559 parameter.parent = classToIr(cls);
563 parameter.parent = classToIr(cls); 560 } else {
561 FunctionElement method = variable.typeDeclaration;
562 parameter.parent = functionToIr(method).function;
563 }
564 parameter.bound = typeToIr(variable.bound); 564 parameter.bound = typeToIr(variable.bound);
565 }); 565 });
566 return parameter; 566 return parameter;
567 }); 567 });
568 } 568 }
569 569
570 List<ir.TypeParameter> typeVariablesToIr(List<DartType> variables) { 570 List<ir.TypeParameter> typeVariablesToIr(List<DartType> variables) {
571 List<ir.TypeParameter> result = 571 List<ir.TypeParameter> result =
572 new List<ir.TypeParameter>(variables.length); 572 new List<ir.TypeParameter>(variables.length);
573 for (int i = 0; i < variables.length; i++) { 573 for (int i = 0; i < variables.length; i++) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 } 763 }
764 764
765 class ConstructorTarget { 765 class ConstructorTarget {
766 final ConstructorElement element; 766 final ConstructorElement element;
767 final DartType type; 767 final DartType type;
768 768
769 ConstructorTarget(this.element, this.type); 769 ConstructorTarget(this.element, this.type);
770 770
771 String toString() => "ConstructorTarget($element, $type)"; 771 String toString() => "ConstructorTarget($element, $type)";
772 } 772 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/kernel/kernel_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698