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

Side by Side Diff: lib/compiler/implementation/elements/elements.dart

Issue 10947024: Made dart2js constructor lookup logic "private"-aware, fixed 4740 bug. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated Peter's comments and feedback. Created 8 years, 2 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 #library('elements'); 5 #library('elements');
6 6
7 #import('dart:uri'); 7 #import('dart:uri');
8 8
9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed.
10 #import('../../compiler.dart', prefix: 'api_e'); 10 #import('../../compiler.dart', prefix: 'api_e');
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 } 1470 }
1471 SourceString fieldName = fieldMember.name; 1471 SourceString fieldName = fieldMember.name;
1472 while (true) { 1472 while (true) {
1473 Element foundMember = lookupClass.lookupMember(fieldName); 1473 Element foundMember = lookupClass.lookupMember(fieldName);
1474 if (foundMember == fieldMember) return false; 1474 if (foundMember == fieldMember) return false;
1475 if (foundMember.isField()) return true; 1475 if (foundMember.isField()) return true;
1476 lookupClass = foundMember.getEnclosingClass().superclass; 1476 lookupClass = foundMember.getEnclosingClass().superclass;
1477 } 1477 }
1478 } 1478 }
1479 1479
1480 Element lookupConstructor(SourceString className, 1480 Element validateConstructorLookupResults(Selector selector,
1481 [SourceString constructorName = 1481 Element result,
1482 const SourceString(''), 1482 Element noMatch(Element)) {
1483 Element noMatch(Element)]) { 1483 if (result === null
1484 // TODO(karlklose): have a map from class names to a map of constructors 1484 || !result.isConstructor()
1485 // instead of creating the name here? 1485 || (selector.name.isPrivate()
1486 && result.getLibrary() != selector.library)) {
1487 result = noMatch !== null ? noMatch(result) : null;
1488 }
1489 return result;
1490 }
1491
1492 // TODO(aprelev@gmail.com): Peter believes that it would be great to
1493 // make noMatch a required argument. Peter's suspicion is that most
1494 // callers of this method would benefit from using the noMatch method.
1495 Element lookupConstructor(Selector selector, [Element noMatch(Element)]) {
1486 SourceString normalizedName; 1496 SourceString normalizedName;
1487 if (constructorName !== const SourceString('')) { 1497 SourceString className = this.name;
1498 SourceString constructorName = selector.name;
1499 if (constructorName !== const SourceString('') &&
1500 ((className === null) ||
1501 (constructorName.slowToString() != className.slowToString()))) {
1488 normalizedName = Elements.constructConstructorName(className, 1502 normalizedName = Elements.constructConstructorName(className,
1489 constructorName); 1503 constructorName);
1490 } else { 1504 } else {
1491 normalizedName = className; 1505 normalizedName = className;
1492 } 1506 }
1493 Element result = localLookup(normalizedName); 1507 Element result = localLookup(normalizedName);
1494 if (result === null || !result.isConstructor()) { 1508 return validateConstructorLookupResults(selector, result, noMatch);
1495 result = noMatch !== null ? noMatch(result) : null; 1509 }
1496 } 1510
1497 return result; 1511 Element lookupFactoryConstructor(Selector selector,
1512 [Element noMatch(Element)]) {
1513 SourceString constructorName = selector.name;
1514 Element result = localLookup(constructorName);
1515 return validateConstructorLookupResults(selector, result, noMatch);
1498 } 1516 }
1499 1517
1500 bool get hasConstructor { 1518 bool get hasConstructor {
1501 // Search in scope to be sure we search patched constructors. 1519 // Search in scope to be sure we search patched constructors.
1502 for (var element in localScope.getValues()) { 1520 for (var element in localScope.getValues()) {
1503 if (element.isConstructor()) return true; 1521 if (element.isConstructor()) return true;
1504 } 1522 }
1505 return false; 1523 return false;
1506 } 1524 }
1507 1525
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 1965
1948 MetadataAnnotation ensureResolved(Compiler compiler) { 1966 MetadataAnnotation ensureResolved(Compiler compiler) {
1949 if (resolutionState == STATE_NOT_STARTED) { 1967 if (resolutionState == STATE_NOT_STARTED) {
1950 compiler.resolver.resolveMetadataAnnotation(this); 1968 compiler.resolver.resolveMetadataAnnotation(this);
1951 } 1969 }
1952 return this; 1970 return this;
1953 } 1971 }
1954 1972
1955 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 1973 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1956 } 1974 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/compile_time_constants.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698