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

Side by Side Diff: lib/compiler/implementation/dart_backend/placeholder_collector.dart

Issue 10861029: Properly rename type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | lib/compiler/implementation/dart_backend/renamer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 class LocalPlaceholder implements Hashable { 5 class LocalPlaceholder implements Hashable {
6 final String identifier; 6 final String identifier;
7 final Set<Node> nodes; 7 final Set<Node> nodes;
8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); 8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>();
9 int hashCode() => identifier.hashCode(); 9 int hashCode() => identifier.hashCode();
10 String toString() => 10 String toString() =>
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
352 static bool isDynamicType(TypeAnnotation typeAnnotation) { 352 static bool isDynamicType(TypeAnnotation typeAnnotation) {
353 if (!isPlainTypeName(typeAnnotation)) return false; 353 if (!isPlainTypeName(typeAnnotation)) return false;
354 String name = typeAnnotation.typeName.asIdentifier().source.slowToString(); 354 String name = typeAnnotation.typeName.asIdentifier().source.slowToString();
355 return name == 'Dynamic'; 355 return name == 'Dynamic';
356 } 356 }
357 357
358 visitTypeAnnotation(TypeAnnotation node) { 358 visitTypeAnnotation(TypeAnnotation node) {
359 // Poor man generic variables resolution. 359 // Poor man generic variables resolution.
360 // TODO(antonm): get rid of it once resolver can deal with it. 360 // TODO(antonm): get rid of it once resolver can deal with it.
361 if (isPlainTypeName(node) && currentElement is TypeDeclarationElement) { 361 TypeDeclarationElement typeDeclarationElement;
362 if (currentElement is TypeDeclarationElement) {
363 typeDeclarationElement = currentElement;
364 } else {
365 typeDeclarationElement = currentElement.getEnclosingClass();
366 }
367 if (typeDeclarationElement !== null && isPlainTypeName(node)) {
362 SourceString name = node.typeName.asIdentifier().source; 368 SourceString name = node.typeName.asIdentifier().source;
363 TypeDeclarationElement typeElement = currentElement; 369 for (TypeVariableType parameter in typeDeclarationElement.typeVariables) {
364 for (TypeVariableType parameter in typeElement.typeVariables) {
365 if (parameter.name == name) { 370 if (parameter.name == name) {
366 // type annotation matches one of parameters, shouldn't be renamed. 371 makeTypePlaceholder(node, parameter);
367 return; 372 return;
368 } 373 }
369 } 374 }
370 } 375 }
371 final type = compiler.resolveTypeAnnotation(currentElement, node); 376 final type = compiler.resolveTypeAnnotation(currentElement, node);
372 if (type is InterfaceType || type is TypedefType) { 377 if (type is InterfaceType || type is TypedefType) {
373 var target = node.typeName; 378 var target = node.typeName;
374 if (node.typeName is Send) { 379 if (node.typeName is Send) {
375 final element = treeElements[node]; 380 final element = treeElements[node];
376 if (element !== null) { 381 if (element !== null) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 tryMakeLocalPlaceholder(element, node.name); 439 tryMakeLocalPlaceholder(element, node.name);
435 } 440 }
436 } 441 }
437 } 442 }
438 node.visitChildren(this); 443 node.visitChildren(this);
439 } 444 }
440 445
441 visitClassNode(ClassNode node) { 446 visitClassNode(ClassNode node) {
442 assert(currentElement is ClassElement); 447 assert(currentElement is ClassElement);
443 makeElementPlaceholder(node.name, currentElement); 448 makeElementPlaceholder(node.name, currentElement);
444 node.visitChildren(this); 449 node.visitChildren(this);
Roman 2012/08/22 08:32:07 probably my last change in ClassNode affects this.
450 if (node.typeParameters !== null) {
451 // Another poor man resolution.
452 final typeVariableTypes =
453 new List<Type>.from(currentElement.typeVariables);
454 int i = 0;
455 for (TypeVariable typeVariable in node.typeParameters) {
456 makeTypePlaceholder(typeVariable.name, typeVariableTypes[i]);
457 i++;
458 }
459 }
445 if (node.defaultClause !== null) { 460 if (node.defaultClause !== null) {
446 // Can't just visit class node's default clause because of the bug in the 461 // Can't just visit class node's default clause because of the bug in the
447 // resolver, it just crashes when it meets type variable. 462 // resolver, it just crashes when it meets type variable.
448 Type defaultType = (currentElement as ClassElement).defaultClass; 463 Type defaultType = (currentElement as ClassElement).defaultClass;
449 assert(defaultType !== null); 464 assert(defaultType !== null);
450 makeTypePlaceholder(node.defaultClause.typeName, defaultType); 465 makeTypePlaceholder(node.defaultClause.typeName, defaultType);
451 visit(node.defaultClause.typeArguments); 466 visit(node.defaultClause.typeArguments);
452 } 467 }
453 } 468 }
454 469
455 visitTypedef(Typedef node) { 470 visitTypedef(Typedef node) {
456 assert(currentElement is TypedefElement); 471 assert(currentElement is TypedefElement);
457 makeElementPlaceholder(node.name, currentElement); 472 makeElementPlaceholder(node.name, currentElement);
458 node.visitChildren(this); 473 node.visitChildren(this);
459 } 474 }
460 } 475 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/dart_backend/renamer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698