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

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

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Update status files and update test-generator for checked mode. 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
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 '../common/resolution.dart' show Resolution; 8 import '../common/resolution.dart' show Resolution;
9 import '../core_types.dart' show CommonElements; 9 import '../core_types.dart' show CommonElements;
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (nameSet.contains(typeName)) { 59 if (nameSet.contains(typeName)) {
60 reporter.reportErrorMessage( 60 reporter.reportErrorMessage(
61 typeNode, 61 typeNode,
62 MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, 62 MessageKind.DUPLICATE_TYPE_VARIABLE_NAME,
63 {'typeVariableName': typeName}); 63 {'typeVariableName': typeName});
64 } 64 }
65 nameSet.add(typeName); 65 nameSet.add(typeName);
66 66
67 TypeVariableElementX variableElement = typeVariable.element; 67 TypeVariableElementX variableElement = typeVariable.element;
68 if (typeNode.bound != null) { 68 if (typeNode.bound != null) {
69 DartType boundType = 69 DartType boundType = typeResolver.resolveNominalTypeAnnotation(
70 typeResolver.resolveTypeAnnotation(this, typeNode.bound); 70 this, typeNode.bound, const []);
71 variableElement.boundCache = boundType; 71 variableElement.boundCache = boundType;
72 72
73 void checkTypeVariableBound() { 73 void checkTypeVariableBound() {
74 Link<TypeVariableElement> seenTypeVariables = 74 Link<TypeVariableElement> seenTypeVariables =
75 const Link<TypeVariableElement>(); 75 const Link<TypeVariableElement>();
76 seenTypeVariables = seenTypeVariables.prepend(variableElement); 76 seenTypeVariables = seenTypeVariables.prepend(variableElement);
77 DartType bound = boundType; 77 DartType bound = boundType;
78 while (bound.isTypeVariable) { 78 while (bound.isTypeVariable) {
79 TypeVariableElement element = bound.element; 79 TypeVariableElement element = bound.element;
80 if (seenTypeVariables.contains(element)) { 80 if (seenTypeVariables.contains(element)) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 244
245 EnumCreator creator = 245 EnumCreator creator =
246 new EnumCreator(reporter, resolution.commonElements, element); 246 new EnumCreator(reporter, resolution.commonElements, element);
247 creator.createMembers(); 247 creator.createMembers();
248 return enumType; 248 return enumType;
249 } 249 }
250 250
251 /// Resolves the mixed type for [mixinNode] and checks that the mixin type 251 /// Resolves the mixed type for [mixinNode] and checks that the mixin type
252 /// is a valid, non-blacklisted interface type. The mixin type is returned. 252 /// is a valid, non-blacklisted interface type. The mixin type is returned.
253 DartType checkMixinType(TypeAnnotation mixinNode) { 253 DartType checkMixinType(NominalTypeAnnotation mixinNode) {
254 DartType mixinType = resolveType(mixinNode); 254 DartType mixinType = resolveNominalType(mixinNode);
255 if (isBlackListed(mixinType)) { 255 if (isBlackListed(mixinType)) {
256 reporter.reportErrorMessage( 256 reporter.reportErrorMessage(
257 mixinNode, MessageKind.CANNOT_MIXIN, {'type': mixinType}); 257 mixinNode, MessageKind.CANNOT_MIXIN, {'type': mixinType});
258 } else if (mixinType.isTypeVariable) { 258 } else if (mixinType.isTypeVariable) {
259 reporter.reportErrorMessage(mixinNode, MessageKind.CLASS_NAME_EXPECTED); 259 reporter.reportErrorMessage(mixinNode, MessageKind.CLASS_NAME_EXPECTED);
260 } else if (mixinType.isMalformed) { 260 } else if (mixinType.isMalformed) {
261 reporter.reportErrorMessage(mixinNode, MessageKind.CANNOT_MIXIN_MALFORMED, 261 reporter.reportErrorMessage(mixinNode, MessageKind.CANNOT_MIXIN_MALFORMED,
262 {'className': element.name, 'malformedType': mixinType}); 262 {'className': element.name, 'malformedType': mixinType});
263 } else if (mixinType.isEnumType) { 263 } else if (mixinType.isEnumType) {
264 reporter.reportErrorMessage(mixinNode, MessageKind.CANNOT_MIXIN_ENUM, 264 reporter.reportErrorMessage(mixinNode, MessageKind.CANNOT_MIXIN_ENUM,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // the mixin for this application to avoid getting into 430 // the mixin for this application to avoid getting into
431 // infinite recursion when traversing members. 431 // infinite recursion when traversing members.
432 return null; 432 return null;
433 } 433 }
434 previous = current; 434 previous = current;
435 current = currentMixinApplication.mixin; 435 current = currentMixinApplication.mixin;
436 } 436 }
437 return mixinType; 437 return mixinType;
438 } 438 }
439 439
440 DartType resolveType(TypeAnnotation node) { 440 DartType resolveNominalType(NominalTypeAnnotation node) {
441 return typeResolver.resolveTypeAnnotation(this, node); 441 return typeResolver.resolveNominalTypeAnnotation(this, node, const []);
442 } 442 }
443 443
444 DartType resolveSupertype(ClassElement cls, TypeAnnotation superclass) { 444 DartType resolveSupertype(ClassElement cls, NominalTypeAnnotation superclass) {
Siggi Cherem (dart-lang) 2016/12/29 22:46:57 long line (we just run dartfmt before submitting)
floitsch 2016/12/30 14:55:47 done. didn't know that dartfmt was accepted in dar
Siggi Cherem (dart-lang) 2017/01/03 23:23:54 :)
445 DartType supertype = resolveType(superclass); 445 DartType supertype = resolveNominalType(superclass);
446 if (supertype != null) { 446 if (supertype != null) {
447 if (supertype.isMalformed) { 447 if (supertype.isMalformed) {
448 reporter.reportErrorMessage( 448 reporter.reportErrorMessage(
449 superclass, 449 superclass,
450 MessageKind.CANNOT_EXTEND_MALFORMED, 450 MessageKind.CANNOT_EXTEND_MALFORMED,
451 {'className': element.name, 'malformedType': supertype}); 451 {'className': element.name, 'malformedType': supertype});
452 return objectType; 452 return objectType;
453 } else if (supertype.isEnumType) { 453 } else if (supertype.isEnumType) {
454 reporter.reportErrorMessage(superclass, MessageKind.CANNOT_EXTEND_ENUM, 454 reporter.reportErrorMessage(superclass, MessageKind.CANNOT_EXTEND_ENUM,
455 {'className': element.name, 'enumType': supertype}); 455 {'className': element.name, 'enumType': supertype});
456 return objectType; 456 return objectType;
457 } else if (!supertype.isInterfaceType) { 457 } else if (!supertype.isInterfaceType) {
458 reporter.reportErrorMessage( 458 reporter.reportErrorMessage(
459 superclass.typeName, MessageKind.CLASS_NAME_EXPECTED); 459 superclass.typeName, MessageKind.CLASS_NAME_EXPECTED);
460 return objectType; 460 return objectType;
461 } else if (isBlackListed(supertype)) { 461 } else if (isBlackListed(supertype)) {
462 reporter.reportErrorMessage( 462 reporter.reportErrorMessage(
463 superclass, MessageKind.CANNOT_EXTEND, {'type': supertype}); 463 superclass, MessageKind.CANNOT_EXTEND, {'type': supertype});
464 return objectType; 464 return objectType;
465 } 465 }
466 } 466 }
467 return supertype; 467 return supertype;
468 } 468 }
469 469
470 Link<DartType> resolveInterfaces(NodeList interfaces, Node superclass) { 470 Link<DartType> resolveInterfaces(NodeList interfaces, Node superclass) {
471 Link<DartType> result = const Link<DartType>(); 471 Link<DartType> result = const Link<DartType>();
472 if (interfaces == null) return result; 472 if (interfaces == null) return result;
473 for (Link<Node> link = interfaces.nodes; !link.isEmpty; link = link.tail) { 473 for (Link<Node> link = interfaces.nodes; !link.isEmpty; link = link.tail) {
474 DartType interfaceType = resolveType(link.head); 474 DartType interfaceType = resolveNominalType(link.head);
475 if (interfaceType != null) { 475 if (interfaceType != null) {
476 if (interfaceType.isMalformed) { 476 if (interfaceType.isMalformed) {
477 reporter.reportErrorMessage( 477 reporter.reportErrorMessage(
478 link.head, 478 link.head,
479 MessageKind.CANNOT_IMPLEMENT_MALFORMED, 479 MessageKind.CANNOT_IMPLEMENT_MALFORMED,
480 {'className': element.name, 'malformedType': interfaceType}); 480 {'className': element.name, 'malformedType': interfaceType});
481 } else if (interfaceType.isEnumType) { 481 } else if (interfaceType.isEnumType) {
482 reporter.reportErrorMessage( 482 reporter.reportErrorMessage(
483 link.head, 483 link.head,
484 MessageKind.CANNOT_IMPLEMENT_ENUM, 484 MessageKind.CANNOT_IMPLEMENT_ENUM,
485 {'className': element.name, 'enumType': interfaceType}); 485 {'className': element.name, 'enumType': interfaceType});
486 } else if (!interfaceType.isInterfaceType) { 486 } else if (!interfaceType.isInterfaceType) {
487 // TODO(johnniwinther): Handle dynamic. 487 // TODO(johnniwinther): Handle dynamic.
488 TypeAnnotation typeAnnotation = link.head; 488 NominalTypeAnnotation typeAnnotation = link.head;
489 reporter.reportErrorMessage( 489 reporter.reportErrorMessage(
490 typeAnnotation.typeName, MessageKind.CLASS_NAME_EXPECTED); 490 typeAnnotation.typeName, MessageKind.CLASS_NAME_EXPECTED);
491 } else { 491 } else {
492 if (interfaceType == element.supertype) { 492 if (interfaceType == element.supertype) {
493 reporter.reportErrorMessage( 493 reporter.reportErrorMessage(
494 superclass, 494 superclass,
495 MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS, 495 MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS,
496 {'type': interfaceType}); 496 {'type': interfaceType});
497 reporter.reportErrorMessage( 497 reporter.reportErrorMessage(
498 link.head, 498 link.head,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 node.superclass.accept(this); 603 node.superclass.accept(this);
604 visitNodeList(node.mixins); 604 visitNodeList(node.mixins);
605 } 605 }
606 606
607 void visitNamedMixinApplication(NamedMixinApplication node) { 607 void visitNamedMixinApplication(NamedMixinApplication node) {
608 node.superclass.accept(this); 608 node.superclass.accept(this);
609 visitNodeList(node.mixins); 609 visitNodeList(node.mixins);
610 visitNodeList(node.interfaces); 610 visitNodeList(node.interfaces);
611 } 611 }
612 612
613 void visitTypeAnnotation(TypeAnnotation node) { 613 void visitNominalTypeAnnotation(NominalTypeAnnotation node) {
614 node.typeName.accept(this); 614 node.typeName.accept(this);
615 } 615 }
616 616
617 void visitIdentifier(Identifier node) { 617 void visitIdentifier(Identifier node) {
618 Element element = lookupInScope(reporter, node, context, node.source); 618 Element element = lookupInScope(reporter, node, context, node.source);
619 if (element != null && element.isClass) { 619 if (element != null && element.isClass) {
620 loadSupertype(element, node); 620 loadSupertype(element, node);
621 } 621 }
622 } 622 }
623 623
(...skipping 14 matching lines...) Expand all
638 Identifier selector = node.selector.asIdentifier(); 638 Identifier selector = node.selector.asIdentifier();
639 var e = prefixElement.lookupLocalMember(selector.source); 639 var e = prefixElement.lookupLocalMember(selector.source);
640 if (e == null || !e.impliesType) { 640 if (e == null || !e.impliesType) {
641 reporter.reportErrorMessage(node.selector, 641 reporter.reportErrorMessage(node.selector,
642 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.selector}); 642 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.selector});
643 return; 643 return;
644 } 644 }
645 loadSupertype(e, node); 645 loadSupertype(e, node);
646 } 646 }
647 } 647 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698