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

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

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 years, 11 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/compiler/lib/src/kernel/error.dart ('k') | 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
11 import '../common.dart'; 11 import '../common.dart';
12 import '../common/names.dart'; 12 import '../common/names.dart';
13 import '../compiler.dart' show Compiler; 13 import '../compiler.dart' show Compiler;
14 import '../constants/expressions.dart' 14 import '../constants/expressions.dart'
15 show ConstantExpression, TypeConstantExpression; 15 show ConstantExpression, TypeConstantExpression;
16 import '../elements/resolution_types.dart' 16 import '../elements/resolution_types.dart'
17 show DartType, FunctionType, InterfaceType, TypeKind, TypeVariableType; 17 show
18 ResolutionDartType,
19 ResolutionFunctionType,
20 ResolutionInterfaceType,
21 ResolutionTypeKind,
22 ResolutionTypeVariableType;
18 import '../diagnostics/messages.dart' show MessageKind; 23 import '../diagnostics/messages.dart' show MessageKind;
19 import '../diagnostics/spannable.dart' show Spannable; 24 import '../diagnostics/spannable.dart' show Spannable;
20 import '../elements/elements.dart' 25 import '../elements/elements.dart'
21 show 26 show
22 ClassElement, 27 ClassElement,
23 ConstructorElement, 28 ConstructorElement,
24 Element, 29 Element,
25 ExportElement, 30 ExportElement,
26 FieldElement, 31 FieldElement,
27 FunctionElement, 32 FunctionElement,
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 for (ir.Field field in remainingFields) { 293 for (ir.Field field in remainingFields) {
289 if (field.initializer == null) { 294 if (field.initializer == null) {
290 field.initializer = new ir.NullLiteral()..parent = field; 295 field.initializer = new ir.NullLiteral()..parent = field;
291 } 296 }
292 } 297 }
293 } 298 }
294 } 299 }
295 300
296 bool hasHierarchyProblem(ClassElement cls) => cls.hasIncompleteHierarchy; 301 bool hasHierarchyProblem(ClassElement cls) => cls.hasIncompleteHierarchy;
297 302
298 ir.InterfaceType interfaceTypeToIr(InterfaceType type) { 303 ir.InterfaceType interfaceTypeToIr(ResolutionInterfaceType type) {
299 ir.Class cls = classToIr(type.element); 304 ir.Class cls = classToIr(type.element);
300 if (type.typeArguments.isEmpty) { 305 if (type.typeArguments.isEmpty) {
301 return cls.rawType; 306 return cls.rawType;
302 } else { 307 } else {
303 return new ir.InterfaceType(cls, typesToIr(type.typeArguments)); 308 return new ir.InterfaceType(cls, typesToIr(type.typeArguments));
304 } 309 }
305 } 310 }
306 311
307 ir.Supertype supertypeToIr(InterfaceType type) { 312 ir.Supertype supertypeToIr(ResolutionInterfaceType type) {
308 ir.Class cls = classToIr(type.element); 313 ir.Class cls = classToIr(type.element);
309 if (type.typeArguments.isEmpty) { 314 if (type.typeArguments.isEmpty) {
310 return cls.asRawSupertype; 315 return cls.asRawSupertype;
311 } else { 316 } else {
312 return new ir.Supertype(cls, typesToIr(type.typeArguments)); 317 return new ir.Supertype(cls, typesToIr(type.typeArguments));
313 } 318 }
314 } 319 }
315 320
316 ir.FunctionType functionTypeToIr(FunctionType type) { 321 ir.FunctionType functionTypeToIr(ResolutionFunctionType type) {
317 List<ir.TypeParameter> typeParameters = <ir.TypeParameter>[]; 322 List<ir.TypeParameter> typeParameters = <ir.TypeParameter>[];
318 int requiredParameterCount = type.parameterTypes.length; 323 int requiredParameterCount = type.parameterTypes.length;
319 List<ir.DartType> positionalParameters = 324 List<ir.DartType> positionalParameters =
320 new List<ir.DartType>.from(typesToIr(type.parameterTypes)) 325 new List<ir.DartType>.from(typesToIr(type.parameterTypes))
321 ..addAll(typesToIr(type.optionalParameterTypes)); 326 ..addAll(typesToIr(type.optionalParameterTypes));
322 List<ir.NamedType> namedParameters = new List<ir.NamedType>.generate( 327 List<ir.NamedType> namedParameters = new List<ir.NamedType>.generate(
323 type.namedParameters.length, 328 type.namedParameters.length,
324 (i) => new ir.NamedType( 329 (i) => new ir.NamedType(
325 type.namedParameters[i], typeToIr(type.namedParameterTypes[i]))); 330 type.namedParameters[i], typeToIr(type.namedParameterTypes[i])));
326 ir.DartType returnType = typeToIr(type.returnType); 331 ir.DartType returnType = typeToIr(type.returnType);
327 332
328 return new ir.FunctionType(positionalParameters, returnType, 333 return new ir.FunctionType(positionalParameters, returnType,
329 namedParameters: namedParameters, 334 namedParameters: namedParameters,
330 typeParameters: typeParameters, 335 typeParameters: typeParameters,
331 requiredParameterCount: requiredParameterCount); 336 requiredParameterCount: requiredParameterCount);
332 } 337 }
333 338
334 ir.TypeParameterType typeVariableTypeToIr(TypeVariableType type) { 339 ir.TypeParameterType typeVariableTypeToIr(ResolutionTypeVariableType type) {
335 return new ir.TypeParameterType(typeVariableToIr(type.element)); 340 return new ir.TypeParameterType(typeVariableToIr(type.element));
336 } 341 }
337 342
338 List<ir.DartType> typesToIr(List<DartType> types) { 343 List<ir.DartType> typesToIr(List<ResolutionDartType> types) {
339 List<ir.DartType> result = new List<ir.DartType>(types.length); 344 List<ir.DartType> result = new List<ir.DartType>(types.length);
340 for (int i = 0; i < types.length; i++) { 345 for (int i = 0; i < types.length; i++) {
341 result[i] = typeToIr(types[i]); 346 result[i] = typeToIr(types[i]);
342 } 347 }
343 return result; 348 return result;
344 } 349 }
345 350
346 List<ir.Supertype> supertypesToIr(List<DartType> types) { 351 List<ir.Supertype> supertypesToIr(List<ResolutionDartType> types) {
347 List<ir.Supertype> result = new List<ir.Supertype>(types.length); 352 List<ir.Supertype> result = new List<ir.Supertype>(types.length);
348 for (int i = 0; i < types.length; i++) { 353 for (int i = 0; i < types.length; i++) {
349 result[i] = supertypeToIr(types[i]); 354 result[i] = supertypeToIr(types[i]);
350 } 355 }
351 return result; 356 return result;
352 } 357 }
353 358
354 ir.DartType typeToIr(DartType type) { 359 ir.DartType typeToIr(ResolutionDartType type) {
355 switch (type.kind) { 360 switch (type.kind) {
356 case TypeKind.FUNCTION: 361 case ResolutionTypeKind.FUNCTION:
357 return functionTypeToIr(type); 362 return functionTypeToIr(type);
358 363
359 case TypeKind.INTERFACE: 364 case ResolutionTypeKind.INTERFACE:
360 return interfaceTypeToIr(type); 365 return interfaceTypeToIr(type);
361 366
362 case TypeKind.TYPEDEF: 367 case ResolutionTypeKind.TYPEDEF:
363 type.computeUnaliased(compiler.resolution); 368 type.computeUnaliased(compiler.resolution);
364 return typeToIr(type.unaliased); 369 return typeToIr(type.unaliased);
365 370
366 case TypeKind.TYPE_VARIABLE: 371 case ResolutionTypeKind.TYPE_VARIABLE:
367 return typeVariableTypeToIr(type); 372 return typeVariableTypeToIr(type);
368 373
369 case TypeKind.MALFORMED_TYPE: 374 case ResolutionTypeKind.MALFORMED_TYPE:
370 return const ir.InvalidType(); 375 return const ir.InvalidType();
371 376
372 case TypeKind.DYNAMIC: 377 case ResolutionTypeKind.DYNAMIC:
373 return const ir.DynamicType(); 378 return const ir.DynamicType();
374 379
375 case TypeKind.VOID: 380 case ResolutionTypeKind.VOID:
376 return const ir.VoidType(); 381 return const ir.VoidType();
377 } 382 }
378 } 383 }
379 384
380 ir.DartType typeLiteralToIr(TypeConstantExpression constant) { 385 ir.DartType typeLiteralToIr(TypeConstantExpression constant) {
381 return typeToIr(constant.type); 386 return typeToIr(constant.type);
382 } 387 }
383 388
384 void setParent(ir.Member member, Element element) { 389 void setParent(ir.Member member, Element element) {
385 if (element.isLocal) { 390 if (element.isLocal) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 /// [factoryTypeParameters]. This serves as a local scope for type variables 492 /// [factoryTypeParameters]. This serves as a local scope for type variables
488 /// resolved inside the factory. 493 /// resolved inside the factory.
489 /// 494 ///
490 /// This method solves the problem that a factory method really is a generic 495 /// This method solves the problem that a factory method really is a generic
491 /// method that has its own type parameters, one for each type parameter in 496 /// method that has its own type parameters, one for each type parameter in
492 /// the enclosing class. 497 /// the enclosing class.
493 void beginFactoryScope(FunctionElement function) { 498 void beginFactoryScope(FunctionElement function) {
494 assert(factoryTypeParameters.isEmpty); 499 assert(factoryTypeParameters.isEmpty);
495 if (!function.isFactoryConstructor) return; 500 if (!function.isFactoryConstructor) return;
496 ClassElement cls = function.enclosingClass; 501 ClassElement cls = function.enclosingClass;
497 for (DartType type in cls.typeVariables) { 502 for (ResolutionDartType type in cls.typeVariables) {
498 if (type.isTypeVariable) { 503 if (type.isTypeVariable) {
499 TypeVariableElement variable = type.element; 504 TypeVariableElement variable = type.element;
500 factoryTypeParameters[variable] = 505 factoryTypeParameters[variable] =
501 new ir.TypeParameter(variable.name, null); 506 new ir.TypeParameter(variable.name, null);
502 } 507 }
503 } 508 }
504 for (DartType type in cls.typeVariables) { 509 for (ResolutionDartType type in cls.typeVariables) {
505 if (type.isTypeVariable) { 510 if (type.isTypeVariable) {
506 TypeVariableElement variable = type.element; 511 TypeVariableElement variable = type.element;
507 factoryTypeParameters[variable].bound = typeToIr(variable.bound); 512 factoryTypeParameters[variable].bound = typeToIr(variable.bound);
508 } 513 }
509 } 514 }
510 } 515 }
511 516
512 /// Ends the local scope started by [beginFactoryScope]. 517 /// Ends the local scope started by [beginFactoryScope].
513 void endFactoryScope(FunctionElement function) { 518 void endFactoryScope(FunctionElement function) {
514 factoryTypeParameters.clear(); 519 factoryTypeParameters.clear();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } else { 578 } else {
574 FunctionElement method = variable.typeDeclaration; 579 FunctionElement method = variable.typeDeclaration;
575 parameter.parent = functionToIr(method).function; 580 parameter.parent = functionToIr(method).function;
576 } 581 }
577 parameter.bound = typeToIr(variable.bound); 582 parameter.bound = typeToIr(variable.bound);
578 }); 583 });
579 return parameter; 584 return parameter;
580 }); 585 });
581 } 586 }
582 587
583 List<ir.TypeParameter> typeVariablesToIr(List<DartType> variables) { 588 List<ir.TypeParameter> typeVariablesToIr(List<ResolutionDartType> variables) {
584 List<ir.TypeParameter> result = 589 List<ir.TypeParameter> result =
585 new List<ir.TypeParameter>(variables.length); 590 new List<ir.TypeParameter>(variables.length);
586 for (int i = 0; i < variables.length; i++) { 591 for (int i = 0; i < variables.length; i++) {
587 TypeVariableType type = variables[i]; 592 ResolutionTypeVariableType type = variables[i];
588 result[i] = typeVariableToIr(type.element); 593 result[i] = typeVariableToIr(type.element);
589 } 594 }
590 return result; 595 return result;
591 } 596 }
592 597
593 ir.TreeNode elementToIr(Element element) { 598 ir.TreeNode elementToIr(Element element) {
594 if (element.isLibrary) return libraryToIr(element); 599 if (element.isLibrary) return libraryToIr(element);
595 if (element.isClass) return classToIr(element); 600 if (element.isClass) return classToIr(element);
596 if (element.isFunction || element.isAccessor) return functionToIr(element); 601 if (element.isFunction || element.isAccessor) return functionToIr(element);
597 if (element.isField) return fieldToIr(element); 602 if (element.isField) return fieldToIr(element);
598 throw "unhandled element: $element"; 603 throw "unhandled element: $element";
599 } 604 }
600 605
601 void debugMessage(Spannable spannable, String message) { 606 void debugMessage(Spannable spannable, String message) {
602 compiler.reporter 607 compiler.reporter
603 .reportHintMessage(spannable, MessageKind.GENERIC, {'text': message}); 608 .reportHintMessage(spannable, MessageKind.GENERIC, {'text': message});
604 } 609 }
605 610
606 void internalError(Spannable spannable, String message) { 611 void internalError(Spannable spannable, String message) {
607 compiler.reporter.internalError(spannable, message); 612 compiler.reporter.internalError(spannable, message);
608 throw message; 613 throw message;
609 } 614 }
610 615
611 forEachLibraryElement(f(LibraryElement library)) { 616 forEachLibraryElement(f(LibraryElement library)) {
612 return compiler.libraryLoader.libraries.forEach(f); 617 return compiler.libraryLoader.libraries.forEach(f);
613 } 618 }
614 619
615 ConstructorTarget computeEffectiveTarget( 620 ConstructorTarget computeEffectiveTarget(
616 ConstructorElement constructor, DartType type) { 621 ConstructorElement constructor, ResolutionDartType type) {
617 constructor = constructor.implementation; 622 constructor = constructor.implementation;
618 Set<ConstructorElement> seen = new Set<ConstructorElement>(); 623 Set<ConstructorElement> seen = new Set<ConstructorElement>();
619 functionToIr(constructor); 624 functionToIr(constructor);
620 while (constructor != constructor.effectiveTarget) { 625 while (constructor != constructor.effectiveTarget) {
621 type = constructor.computeEffectiveTargetType(type); 626 type = constructor.computeEffectiveTargetType(type);
622 if (constructor.isGenerativeConstructor) break; 627 if (constructor.isGenerativeConstructor) break;
623 if (!seen.add(constructor)) break; 628 if (!seen.add(constructor)) break;
624 constructor = constructor.effectiveTarget.implementation; 629 constructor = constructor.effectiveTarget.implementation;
625 if (isSyntheticError(constructor)) break; 630 if (isSyntheticError(constructor)) break;
626 functionToIr(constructor); 631 functionToIr(constructor);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 return getDartCoreMethod('_genericNoSuchMethod'); 778 return getDartCoreMethod('_genericNoSuchMethod');
774 } 779 }
775 780
776 ir.Constructor getFallThroughErrorConstructor() { 781 ir.Constructor getFallThroughErrorConstructor() {
777 return getDartCoreConstructor('FallThroughError', ''); 782 return getDartCoreConstructor('FallThroughError', '');
778 } 783 }
779 } 784 }
780 785
781 class ConstructorTarget { 786 class ConstructorTarget {
782 final ConstructorElement element; 787 final ConstructorElement element;
783 final DartType type; 788 final ResolutionDartType type;
784 789
785 ConstructorTarget(this.element, this.type); 790 ConstructorTarget(this.element, this.type);
786 791
787 String toString() => "ConstructorTarget($element, $type)"; 792 String toString() => "ConstructorTarget($element, $type)";
788 } 793 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/error.dart ('k') | pkg/compiler/lib/src/kernel/kernel_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698