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

Side by Side Diff: dart/frog/leg/resolver.dart

Issue 9724032: Resolve type Dynamic and implement black listing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
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
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.GENERIC, ['cannot extend']);
ahe 2012/03/19 10:51:57 Make real error message.
ahe 2012/03/19 15:31:09 Done.
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.GENERIC, ['cannot implement']);
ahe 2012/03/19 10:51:57 Ditto.
ahe 2012/03/19 15:31:09 Done.
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
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.functionClass);
1437 }
1417 } 1438 }
1418 1439
1419 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { 1440 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> {
1420 VariableDefinitions definitions; 1441 VariableDefinitions definitions;
1421 ResolverVisitor resolver; 1442 ResolverVisitor resolver;
1422 ElementKind kind; 1443 ElementKind kind;
1423 VariableListElement variables; 1444 VariableListElement variables;
1424 1445
1425 VariableDefinitionsVisitor(Compiler compiler, 1446 VariableDefinitionsVisitor(Compiler compiler,
1426 this.definitions, this.resolver, this.kind) 1447 this.definitions, this.resolver, this.kind)
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 1771
1751 TopScope(LibraryElement library) : super(null, library); 1772 TopScope(LibraryElement library) : super(null, library);
1752 Element lookup(SourceString name) { 1773 Element lookup(SourceString name) {
1753 return library.find(name); 1774 return library.find(name);
1754 } 1775 }
1755 1776
1756 Element add(Element element) { 1777 Element add(Element element) {
1757 throw "Cannot add an element in the top scope"; 1778 throw "Cannot add an element in the top scope";
1758 } 1779 }
1759 } 1780 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698