| 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 } | 8 } |
| 9 | 9 |
| 10 class TreeElementMapping implements TreeElements { | 10 class TreeElementMapping implements TreeElements { |
| (...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 variableElement.bound = boundType; | 1256 variableElement.bound = boundType; |
| 1257 } else { | 1257 } else { |
| 1258 variableElement.bound = compiler.objectClass.computeType(compiler); | 1258 variableElement.bound = compiler.objectClass.computeType(compiler); |
| 1259 } | 1259 } |
| 1260 } | 1260 } |
| 1261 } | 1261 } |
| 1262 // Find super type. | 1262 // Find super type. |
| 1263 Type supertype = visit(node.superclass); | 1263 Type supertype = visit(node.superclass); |
| 1264 if (supertype !== null && supertype.element.isExtendable()) { | 1264 if (supertype !== null && supertype.element.isExtendable()) { |
| 1265 classElement.supertype = supertype; | 1265 classElement.supertype = supertype; |
| 1266 if (isBlackListed(supertype)) { |
| 1267 error(node.superclass, MessageKind.CANNOT_EXTEND, [supertype]); |
| 1268 } |
| 1266 } else if (supertype !== null) { | 1269 } else if (supertype !== null) { |
| 1267 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); | 1270 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); |
| 1268 } | 1271 } |
| 1269 if (classElement.name != Types.OBJECT && classElement.supertype === null) { | 1272 if (classElement.name != Types.OBJECT && classElement.supertype === null) { |
| 1270 ClassElement objectElement = context.lookup(Types.OBJECT); | 1273 ClassElement objectElement = context.lookup(Types.OBJECT); |
| 1271 if (objectElement !== null && !objectElement.isResolved) { | 1274 if (objectElement !== null && !objectElement.isResolved) { |
| 1272 compiler.resolver.toResolve.add(objectElement); | 1275 compiler.resolver.toResolve.add(objectElement); |
| 1273 } else if (objectElement === null){ | 1276 } else if (objectElement === null){ |
| 1274 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [Types.OBJECT]); | 1277 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [Types.OBJECT]); |
| 1275 } | 1278 } |
| 1276 classElement.supertype = new SimpleType(Types.OBJECT, objectElement); | 1279 classElement.supertype = new SimpleType(Types.OBJECT, objectElement); |
| 1277 } | 1280 } |
| 1278 if (node.defaultClause !== null) { | 1281 if (node.defaultClause !== null) { |
| 1279 classElement.defaultClass = visit(node.defaultClause); | 1282 classElement.defaultClass = visit(node.defaultClause); |
| 1280 } | 1283 } |
| 1281 for (Link<Node> link = node.interfaces.nodes; | 1284 for (Link<Node> link = node.interfaces.nodes; |
| 1282 !link.isEmpty(); | 1285 !link.isEmpty(); |
| 1283 link = link.tail) { | 1286 link = link.tail) { |
| 1284 Type interfaceType = visit(link.head); | 1287 Type interfaceType = visit(link.head); |
| 1285 if (interfaceType !== null && interfaceType.element.isExtendable()) { | 1288 if (interfaceType !== null && interfaceType.element.isExtendable()) { |
| 1286 classElement.interfaces = | 1289 classElement.interfaces = |
| 1287 classElement.interfaces.prepend(interfaceType); | 1290 classElement.interfaces.prepend(interfaceType); |
| 1291 if (isBlackListed(interfaceType)) { |
| 1292 error(link.head, MessageKind.CANNOT_IMPLEMENT, [interfaceType]); |
| 1293 } |
| 1288 } else { | 1294 } else { |
| 1289 error(link.head, MessageKind.TYPE_NAME_EXPECTED); | 1295 error(link.head, MessageKind.TYPE_NAME_EXPECTED); |
| 1290 } | 1296 } |
| 1291 } | 1297 } |
| 1292 calculateAllSupertypes(classElement, new Set<ClassElement>()); | 1298 calculateAllSupertypes(classElement, new Set<ClassElement>()); |
| 1293 addDefaultConstructorIfNeeded(classElement); | 1299 addDefaultConstructorIfNeeded(classElement); |
| 1294 return classElement.computeType(compiler); | 1300 return classElement.computeType(compiler); |
| 1295 } | 1301 } |
| 1296 | 1302 |
| 1297 Type visitTypeAnnotation(TypeAnnotation node) { | 1303 Type visitTypeAnnotation(TypeAnnotation node) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 element.constructors[element.name] = constructor; | 1413 element.constructors[element.name] = constructor; |
| 1408 Type returnType = compiler.types.voidType; | 1414 Type returnType = compiler.types.voidType; |
| 1409 constructor.type = new FunctionType(returnType, const EmptyLink<Type>(), | 1415 constructor.type = new FunctionType(returnType, const EmptyLink<Type>(), |
| 1410 constructor); | 1416 constructor); |
| 1411 constructor.cachedNode = | 1417 constructor.cachedNode = |
| 1412 new FunctionExpression(new Identifier(element.position()), | 1418 new FunctionExpression(new Identifier(element.position()), |
| 1413 new NodeList.empty(), | 1419 new NodeList.empty(), |
| 1414 new Block(new NodeList.empty()), | 1420 new Block(new NodeList.empty()), |
| 1415 null, null, null, null); | 1421 null, null, null, null); |
| 1416 } | 1422 } |
| 1423 |
| 1424 isBlackListed(Type type) { |
| 1425 LibraryElement lib = classElement.getLibrary(); |
| 1426 return |
| 1427 lib !== compiler.coreLibrary && |
| 1428 lib !== compiler.coreImplLibrary && |
| 1429 lib !== compiler.jsHelperLibrary && |
| 1430 (type.element === compiler.dynamicClass || |
| 1431 type.element === compiler.boolClass || |
| 1432 type.element === compiler.numClass || |
| 1433 type.element === compiler.intClass || |
| 1434 type.element === compiler.doubleClass || |
| 1435 type.element === compiler.stringClass || |
| 1436 type.element === compiler.nullClass || |
| 1437 type.element === compiler.functionClass); |
| 1438 } |
| 1417 } | 1439 } |
| 1418 | 1440 |
| 1419 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { | 1441 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { |
| 1420 VariableDefinitions definitions; | 1442 VariableDefinitions definitions; |
| 1421 ResolverVisitor resolver; | 1443 ResolverVisitor resolver; |
| 1422 ElementKind kind; | 1444 ElementKind kind; |
| 1423 VariableListElement variables; | 1445 VariableListElement variables; |
| 1424 | 1446 |
| 1425 VariableDefinitionsVisitor(Compiler compiler, | 1447 VariableDefinitionsVisitor(Compiler compiler, |
| 1426 this.definitions, this.resolver, this.kind) | 1448 this.definitions, this.resolver, this.kind) |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1750 | 1772 |
| 1751 TopScope(LibraryElement library) : super(null, library); | 1773 TopScope(LibraryElement library) : super(null, library); |
| 1752 Element lookup(SourceString name) { | 1774 Element lookup(SourceString name) { |
| 1753 return library.find(name); | 1775 return library.find(name); |
| 1754 } | 1776 } |
| 1755 | 1777 |
| 1756 Element add(Element element) { | 1778 Element add(Element element) { |
| 1757 throw "Cannot add an element in the top scope"; | 1779 throw "Cannot add an element in the top scope"; |
| 1758 } | 1780 } |
| 1759 } | 1781 } |
| OLD | NEW |