| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 interface TreeElements { | 5 interface TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 Type getType(TypeAnnotation annotation); | 8 Type getType(TypeAnnotation annotation); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 bool isSuperCall, | 360 bool isSuperCall, |
| 361 bool isImplicitSuperCall, | 361 bool isImplicitSuperCall, |
| 362 SourceString constructorName, | 362 SourceString constructorName, |
| 363 Selector selector, | 363 Selector selector, |
| 364 Node diagnosticNode) { | 364 Node diagnosticNode) { |
| 365 ClassElement lookupTarget = constructor.enclosingElement; | 365 ClassElement lookupTarget = constructor.enclosingElement; |
| 366 bool validTarget = true; | 366 bool validTarget = true; |
| 367 FunctionElement result; | 367 FunctionElement result; |
| 368 if (isSuperCall) { | 368 if (isSuperCall) { |
| 369 // Calculate correct lookup target and constructor name. | 369 // Calculate correct lookup target and constructor name. |
| 370 if (lookupTarget.name == Types.OBJECT) { | 370 if (lookupTarget === visitor.compiler.objectClass) { |
| 371 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); | 371 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); |
| 372 } else { | 372 } else { |
| 373 lookupTarget = lookupTarget.supertype.element; | 373 lookupTarget = lookupTarget.supertype.element; |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 // Lookup constructor and try to match it to the selector. | 377 // Lookup constructor and try to match it to the selector. |
| 378 ResolverTask resolver = visitor.compiler.resolver; | 378 ResolverTask resolver = visitor.compiler.resolver; |
| 379 final SourceString className = lookupTarget.name; | 379 final SourceString className = lookupTarget.name; |
| 380 result = lookupTarget.lookupConstructor(className, constructorName); | 380 result = lookupTarget.lookupConstructor(className, constructorName); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 class TypeResolver { | 596 class TypeResolver { |
| 597 final Compiler compiler; | 597 final Compiler compiler; |
| 598 TypeResolver(this.compiler); | 598 TypeResolver(this.compiler); |
| 599 | 599 |
| 600 Element resolveTypeName(Scope context, TypeAnnotation node) { | 600 Element resolveTypeName(Scope context, TypeAnnotation node) { |
| 601 Identifier typeName = node.typeName.asIdentifier(); | 601 Identifier typeName = node.typeName.asIdentifier(); |
| 602 Send send = node.typeName.asSend(); | 602 Send send = node.typeName.asSend(); |
| 603 if (send !== null) { | 603 if (send !== null) { |
| 604 typeName = send.selector; | 604 typeName = send.selector; |
| 605 } | 605 } |
| 606 if (typeName.source == Types.VOID) { | 606 if (typeName.source.stringValue === 'void') { |
| 607 return compiler.types.voidType.element; | 607 return compiler.types.voidType.element; |
| 608 } else if (send !== null) { | 608 } else if (send !== null) { |
| 609 Element e = context.lookup(send.receiver.asIdentifier().source); | 609 Element e = context.lookup(send.receiver.asIdentifier().source); |
| 610 if (e !== null && e.kind === ElementKind.PREFIX) { | 610 if (e !== null && e.kind === ElementKind.PREFIX) { |
| 611 // The receiver is a prefix. Lookup in the imported members. | 611 // The receiver is a prefix. Lookup in the imported members. |
| 612 PrefixElement prefix = e; | 612 PrefixElement prefix = e; |
| 613 return prefix.lookupLocalMember(typeName.source); | 613 return prefix.lookupLocalMember(typeName.source); |
| 614 } else if (e !== null && e.kind === ElementKind.CLASS) { | 614 } else if (e !== null && e.kind === ElementKind.CLASS) { |
| 615 // The receiver is the class part of a named constructor. | 615 // The receiver is the class part of a named constructor. |
| 616 return e; | 616 return e; |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 // Find super type. | 1586 // Find super type. |
| 1587 Type supertype = visit(node.superclass); | 1587 Type supertype = visit(node.superclass); |
| 1588 if (supertype !== null && supertype.element.isExtendable()) { | 1588 if (supertype !== null && supertype.element.isExtendable()) { |
| 1589 classElement.supertype = supertype; | 1589 classElement.supertype = supertype; |
| 1590 if (isBlackListed(supertype)) { | 1590 if (isBlackListed(supertype)) { |
| 1591 error(node.superclass, MessageKind.CANNOT_EXTEND, [supertype]); | 1591 error(node.superclass, MessageKind.CANNOT_EXTEND, [supertype]); |
| 1592 } | 1592 } |
| 1593 } else if (supertype !== null) { | 1593 } else if (supertype !== null) { |
| 1594 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); | 1594 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); |
| 1595 } | 1595 } |
| 1596 if (classElement.name != Types.OBJECT && classElement.supertype === null) { | 1596 final objectElement = compiler.objectClass; |
| 1597 ClassElement objectElement = context.lookup(Types.OBJECT); | 1597 if (classElement !== objectElement && classElement.supertype === null) { |
| 1598 if (objectElement !== null && !objectElement.isResolved) { | 1598 if (objectElement === null) { |
| 1599 compiler.internalError("Internal error: cannot resolve Object", |
| 1600 node: node); |
| 1601 } else if (!objectElement.isResolved) { |
| 1599 compiler.resolver.toResolve.add(objectElement); | 1602 compiler.resolver.toResolve.add(objectElement); |
| 1600 } else if (objectElement === null){ | |
| 1601 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [Types.OBJECT]); | |
| 1602 } | 1603 } |
| 1603 classElement.supertype = new InterfaceType(objectElement); | 1604 classElement.supertype = new InterfaceType(objectElement); |
| 1604 } | 1605 } |
| 1605 if (node.defaultClause !== null) { | 1606 if (node.defaultClause !== null) { |
| 1606 classElement.defaultClass = visit(node.defaultClause); | 1607 classElement.defaultClass = visit(node.defaultClause); |
| 1607 } | 1608 } |
| 1608 for (Link<Node> link = node.interfaces.nodes; | 1609 for (Link<Node> link = node.interfaces.nodes; |
| 1609 !link.isEmpty(); | 1610 !link.isEmpty(); |
| 1610 link = link.tail) { | 1611 link = link.tail) { |
| 1611 Type interfaceType = visit(link.head); | 1612 Type interfaceType = visit(link.head); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 | 2094 |
| 2094 TopScope(LibraryElement library) : super(null, library); | 2095 TopScope(LibraryElement library) : super(null, library); |
| 2095 Element lookup(SourceString name) { | 2096 Element lookup(SourceString name) { |
| 2096 return library.find(name); | 2097 return library.find(name); |
| 2097 } | 2098 } |
| 2098 | 2099 |
| 2099 Element add(Element newElement) { | 2100 Element add(Element newElement) { |
| 2100 throw "Cannot add an element in the top scope"; | 2101 throw "Cannot add an element in the top scope"; |
| 2101 } | 2102 } |
| 2102 } | 2103 } |
| OLD | NEW |