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

Side by Side Diff: pkg/compiler/lib/src/resolution/class_hierarchy.dart

Issue 1421003004: Add CoreClasses (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. Created 5 years, 1 month 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 dart2js.resolution.class_hierarchy; 5 library dart2js.resolution.class_hierarchy;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../compiler.dart' show 8 import '../compiler.dart' show
9 Compiler; 9 Compiler;
10 import '../core_types.dart' show
11 CoreClasses,
12 CoreTypes;
10 import '../dart_types.dart'; 13 import '../dart_types.dart';
11 import '../elements/elements.dart'; 14 import '../elements/elements.dart';
12 import '../elements/modelx.dart' show 15 import '../elements/modelx.dart' show
13 BaseClassElementX, 16 BaseClassElementX,
14 ErroneousElementX, 17 ErroneousElementX,
15 MixinApplicationElementX, 18 MixinApplicationElementX,
16 SynthesizedConstructorElementX, 19 SynthesizedConstructorElementX,
17 TypeVariableElementX; 20 TypeVariableElementX;
18 import '../ordered_typeset.dart' show 21 import '../ordered_typeset.dart' show
19 OrderedTypeSet, 22 OrderedTypeSet,
(...skipping 22 matching lines...) Expand all
42 final TypeDeclarationElement enclosingElement; 45 final TypeDeclarationElement enclosingElement;
43 TypeDeclarationElement get element => enclosingElement; 46 TypeDeclarationElement get element => enclosingElement;
44 47
45 TypeDefinitionVisitor(Compiler compiler, 48 TypeDefinitionVisitor(Compiler compiler,
46 TypeDeclarationElement element, 49 TypeDeclarationElement element,
47 ResolutionRegistry registry) 50 ResolutionRegistry registry)
48 : this.enclosingElement = element, 51 : this.enclosingElement = element,
49 scope = Scope.buildEnclosingScope(element), 52 scope = Scope.buildEnclosingScope(element),
50 super(compiler, registry); 53 super(compiler, registry);
51 54
52 DartType get objectType => compiler.objectClass.rawType; 55 DartType get objectType => compiler.coreTypes.objectType;
53 56
54 void resolveTypeVariableBounds(NodeList node) { 57 void resolveTypeVariableBounds(NodeList node) {
55 if (node == null) return; 58 if (node == null) return;
56 59
57 Setlet<String> nameSet = new Setlet<String>(); 60 Setlet<String> nameSet = new Setlet<String>();
58 // Resolve the bounds of type variables. 61 // Resolve the bounds of type variables.
59 Iterator<DartType> types = element.typeVariables.iterator; 62 Iterator<DartType> types = element.typeVariables.iterator;
60 Link<Node> nodeLink = node.nodes; 63 Link<Node> nodeLink = node.nodes;
61 while (!nodeLink.isEmpty) { 64 while (!nodeLink.isEmpty) {
62 types.moveNext(); 65 types.moveNext();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 370
368 void doApplyMixinTo(MixinApplicationElementX mixinApplication, 371 void doApplyMixinTo(MixinApplicationElementX mixinApplication,
369 DartType supertype, 372 DartType supertype,
370 DartType mixinType) { 373 DartType mixinType) {
371 Node node = mixinApplication.parseNode(resolution.parsing); 374 Node node = mixinApplication.parseNode(resolution.parsing);
372 375
373 if (mixinApplication.supertype != null) { 376 if (mixinApplication.supertype != null) {
374 // [supertype] is not null if there was a cycle. 377 // [supertype] is not null if there was a cycle.
375 assert(invariant(node, compiler.compilationFailed)); 378 assert(invariant(node, compiler.compilationFailed));
376 supertype = mixinApplication.supertype; 379 supertype = mixinApplication.supertype;
377 assert(invariant(node, supertype.element == compiler.objectClass)); 380 assert(invariant(node, supertype.isObject));
378 } else { 381 } else {
379 mixinApplication.supertype = supertype; 382 mixinApplication.supertype = supertype;
380 } 383 }
381 384
382 // Named mixin application may have an 'implements' clause. 385 // Named mixin application may have an 'implements' clause.
383 NamedMixinApplication namedMixinApplication = 386 NamedMixinApplication namedMixinApplication =
384 node.asNamedMixinApplication(); 387 node.asNamedMixinApplication();
385 Link<DartType> interfaces = (namedMixinApplication != null) 388 Link<DartType> interfaces = (namedMixinApplication != null)
386 ? resolveInterfaces(namedMixinApplication.interfaces, 389 ? resolveInterfaces(namedMixinApplication.interfaces,
387 namedMixinApplication.superclass) 390 namedMixinApplication.superclass)
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 578
576 addAllSupertypes(allSupertypes, supertype); 579 addAllSupertypes(allSupertypes, supertype);
577 for (Link<DartType> interfaces = cls.interfaces; 580 for (Link<DartType> interfaces = cls.interfaces;
578 !interfaces.isEmpty; 581 !interfaces.isEmpty;
579 interfaces = interfaces.tail) { 582 interfaces = interfaces.tail) {
580 addAllSupertypes(allSupertypes, interfaces.head); 583 addAllSupertypes(allSupertypes, interfaces.head);
581 } 584 }
582 allSupertypes.add(compiler, cls.computeType(resolution)); 585 allSupertypes.add(compiler, cls.computeType(resolution));
583 cls.allSupertypesAndSelf = allSupertypes.toTypeSet(); 586 cls.allSupertypesAndSelf = allSupertypes.toTypeSet();
584 } else { 587 } else {
585 assert(identical(cls, compiler.objectClass)); 588 assert(cls == compiler.coreClasses.objectClass);
586 cls.allSupertypesAndSelf = 589 cls.allSupertypesAndSelf =
587 new OrderedTypeSet.singleton(cls.computeType(resolution)); 590 new OrderedTypeSet.singleton(cls.computeType(resolution));
588 } 591 }
589 } 592 }
590 593
591 /** 594 /**
592 * Adds [type] and all supertypes of [type] to [allSupertypes] while 595 * Adds [type] and all supertypes of [type] to [allSupertypes] while
593 * substituting type variables. 596 * substituting type variables.
594 */ 597 */
595 void addAllSupertypes(OrderedTypeSetBuilder allSupertypes, 598 void addAllSupertypes(OrderedTypeSetBuilder allSupertypes,
596 InterfaceType type) { 599 InterfaceType type) {
597 ClassElement classElement = type.element; 600 ClassElement classElement = type.element;
598 Link<DartType> supertypes = classElement.allSupertypes; 601 Link<DartType> supertypes = classElement.allSupertypes;
599 assert(invariant(element, supertypes != null, 602 assert(invariant(element, supertypes != null,
600 message: "Supertypes not computed on $classElement " 603 message: "Supertypes not computed on $classElement "
601 "during resolution of $element")); 604 "during resolution of $element"));
602 while (!supertypes.isEmpty) { 605 while (!supertypes.isEmpty) {
603 DartType supertype = supertypes.head; 606 DartType supertype = supertypes.head;
604 allSupertypes.add(compiler, supertype.substByContext(type)); 607 allSupertypes.add(compiler, supertype.substByContext(type));
605 supertypes = supertypes.tail; 608 supertypes = supertypes.tail;
606 } 609 }
607 } 610 }
608 611
609 isBlackListed(DartType type) { 612 isBlackListed(DartType type) {
610 LibraryElement lib = element.library; 613 LibraryElement lib = element.library;
614 CoreTypes coreTypes = compiler.coreTypes;
611 return 615 return
612 !identical(lib, compiler.coreLibrary) && 616 !identical(lib, compiler.coreLibrary) &&
613 !compiler.backend.isBackendLibrary(lib) && 617 !compiler.backend.isBackendLibrary(lib) &&
614 (type.isDynamic || 618 (type.isDynamic ||
615 identical(type.element, compiler.boolClass) || 619 type == coreTypes.boolType ||
616 identical(type.element, compiler.numClass) || 620 type == coreTypes.numType ||
617 identical(type.element, compiler.intClass) || 621 type == coreTypes.intType ||
618 identical(type.element, compiler.doubleClass) || 622 type == coreTypes.doubleType ||
619 identical(type.element, compiler.stringClass) || 623 type == coreTypes.stringType ||
620 identical(type.element, compiler.nullClass)); 624 type == coreTypes.nullType);
621 } 625 }
622 } 626 }
623 627
624 class ClassSupertypeResolver extends CommonResolverVisitor { 628 class ClassSupertypeResolver extends CommonResolverVisitor {
625 Scope context; 629 Scope context;
626 ClassElement classElement; 630 ClassElement classElement;
627 631
628 ClassSupertypeResolver(Compiler compiler, ClassElement cls) 632 ClassSupertypeResolver(Compiler compiler, ClassElement cls)
629 : context = Scope.buildEnclosingScope(cls), 633 : context = Scope.buildEnclosingScope(cls),
630 this.classElement = cls, 634 this.classElement = cls,
631 super(compiler); 635 super(compiler);
632 636
637 CoreClasses get coreClasses => compiler.coreClasses;
638
633 void loadSupertype(ClassElement element, Node from) { 639 void loadSupertype(ClassElement element, Node from) {
634 if (!element.isResolved) { 640 if (!element.isResolved) {
635 compiler.resolver.loadSupertypes(element, from); 641 compiler.resolver.loadSupertypes(element, from);
636 element.ensureResolved(resolution); 642 element.ensureResolved(resolution);
637 } 643 }
638 } 644 }
639 645
640 void visitNodeList(NodeList node) { 646 void visitNodeList(NodeList node) {
641 if (node != null) { 647 if (node != null) {
642 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { 648 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) {
643 link.head.accept(this); 649 link.head.accept(this);
644 } 650 }
645 } 651 }
646 } 652 }
647 653
648 void visitClassNode(ClassNode node) { 654 void visitClassNode(ClassNode node) {
649 if (node.superclass == null) { 655 if (node.superclass == null) {
650 if (!identical(classElement, compiler.objectClass)) { 656 if (classElement != coreClasses.objectClass) {
651 loadSupertype(compiler.objectClass, node); 657 loadSupertype(coreClasses.objectClass, node);
652 } 658 }
653 } else { 659 } else {
654 node.superclass.accept(this); 660 node.superclass.accept(this);
655 } 661 }
656 visitNodeList(node.interfaces); 662 visitNodeList(node.interfaces);
657 } 663 }
658 664
659 void visitEnum(Enum node) { 665 void visitEnum(Enum node) {
660 loadSupertype(compiler.objectClass, node); 666 loadSupertype(coreClasses.objectClass, node);
661 } 667 }
662 668
663 void visitMixinApplication(MixinApplication node) { 669 void visitMixinApplication(MixinApplication node) {
664 node.superclass.accept(this); 670 node.superclass.accept(this);
665 visitNodeList(node.mixins); 671 visitNodeList(node.mixins);
666 } 672 }
667 673
668 void visitNamedMixinApplication(NamedMixinApplication node) { 674 void visitNamedMixinApplication(NamedMixinApplication node) {
669 node.superclass.accept(this); 675 node.superclass.accept(this);
670 visitNodeList(node.mixins); 676 visitNodeList(node.mixins);
(...skipping 30 matching lines...) Expand all
701 if (e == null || !e.impliesType) { 707 if (e == null || !e.impliesType) {
702 reporter.reportErrorMessage( 708 reporter.reportErrorMessage(
703 node.selector, 709 node.selector,
704 MessageKind.CANNOT_RESOLVE_TYPE, 710 MessageKind.CANNOT_RESOLVE_TYPE,
705 {'typeName': node.selector}); 711 {'typeName': node.selector});
706 return; 712 return;
707 } 713 }
708 loadSupertype(e, node); 714 loadSupertype(e, node);
709 } 715 }
710 } 716 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ordered_typeset.dart ('k') | pkg/compiler/lib/src/resolution/class_members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698