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

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: Another try in implementing constructor lookup, without SelectorName this time. Created 8 years, 3 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 #import('../tree/tree.dart'); 9 #import('../tree/tree.dart');
10 #import('../scanner/scannerlib.dart'); 10 #import('../scanner/scannerlib.dart');
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 } 1367 }
1368 SourceString fieldName = fieldMember.name; 1368 SourceString fieldName = fieldMember.name;
1369 while (true) { 1369 while (true) {
1370 Element foundMember = lookupClass.lookupMember(fieldName); 1370 Element foundMember = lookupClass.lookupMember(fieldName);
1371 if (foundMember == fieldMember) return false; 1371 if (foundMember == fieldMember) return false;
1372 if (foundMember.isField()) return true; 1372 if (foundMember.isField()) return true;
1373 lookupClass = foundMember.getEnclosingClass().superclass; 1373 lookupClass = foundMember.getEnclosingClass().superclass;
1374 } 1374 }
1375 } 1375 }
1376 1376
1377 Element lookupConstructor(SourceString className, 1377 Element lookupConstructor(Selector selector, [Element noMatch(Element)]) {
1378 [SourceString constructorName =
1379 const SourceString(''),
1380 Element noMatch(Element)]) {
1381 // TODO(karlklose): have a map from class names to a map of constructors 1378 // TODO(karlklose): have a map from class names to a map of constructors
1382 // instead of creating the name here? 1379 // instead of creating the name here?
1383 SourceString normalizedName; 1380 SourceString normalizedName =
1384 if (constructorName !== const SourceString('')) { 1381 Elements.constructConstructorNameFromOneName(selector.name);
1385 normalizedName = Elements.constructConstructorName(className, 1382
1386 constructorName);
1387 } else {
1388 normalizedName = className;
1389 }
1390 Element result = localLookup(normalizedName); 1383 Element result = localLookup(normalizedName);
1391 if (result === null || !result.isConstructor()) { 1384
1385 if (result === null
1386 || !result.isConstructor()
1387 || (selector.isPrivate() && result.getLibrary() != selector.library)) {
1392 result = noMatch !== null ? noMatch(result) : null; 1388 result = noMatch !== null ? noMatch(result) : null;
1393 } 1389 }
1394 return result; 1390 return result;
1395 } 1391 }
1396 1392
1397 bool get hasConstructor { 1393 bool get hasConstructor {
1398 // Search in scope to be sure we search patched constructors. 1394 // Search in scope to be sure we search patched constructors.
1399 for (var element in localScope.getValues()) { 1395 for (var element in localScope.getValues()) {
1400 if (element.isConstructor()) return true; 1396 if (element.isConstructor()) return true;
1401 } 1397 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 return isLocal(element); 1584 return isLocal(element);
1589 } 1585 }
1590 1586
1591 static SourceString constructConstructorName(SourceString receiver, 1587 static SourceString constructConstructorName(SourceString receiver,
1592 SourceString selector) { 1588 SourceString selector) {
1593 String r = receiver.slowToString(); 1589 String r = receiver.slowToString();
1594 String s = selector.slowToString(); 1590 String s = selector.slowToString();
1595 return new SourceString('$r\$$s'); 1591 return new SourceString('$r\$$s');
1596 } 1592 }
1597 1593
1594 static SourceString constructConstructorNameFromOneName(SourceString name) {
kasperl 2012/09/24 05:52:38 Somehow it would be simpler if the name stored in
ahe 2012/09/24 06:43:31 I'm uncomfortable about adding this method. The me
aam-me 2012/09/25 04:15:18 Okay, got rid of the method and storing normalized
1595 var strName = name.slowToString();
kasperl 2012/09/24 05:52:38 Try to avoid abbreviations. I'd go for dotIndex an
1596 var ndxDot = strName.indexOf(".");
1597 if (ndxDot >= 0) {
1598 return new SourceString(
1599 '${strName.substring(0, ndxDot)}\$'
1600 '${strName.substring(ndxDot + 1, strName.length)}');
1601 } else {
1602 return name;
1603 }
1604 }
1605
1598 static const SourceString OPERATOR_EQUALS = 1606 static const SourceString OPERATOR_EQUALS =
1599 const SourceString(@'operator$eq'); 1607 const SourceString(@'operator$eq');
1600 1608
1601 static SourceString constructOperatorName(SourceString selector, 1609 static SourceString constructOperatorName(SourceString selector,
1602 bool isUnary) { 1610 bool isUnary) {
1603 String str = selector.stringValue; 1611 String str = selector.stringValue;
1604 if (str === '==' || str === '!=') return OPERATOR_EQUALS; 1612 if (str === '==' || str === '!=') return OPERATOR_EQUALS;
1605 1613
1606 if (str === '~') { 1614 if (str === '~') {
1607 str = 'not'; 1615 str = 'not';
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 1798
1791 MetadataAnnotation ensureResolved(Compiler compiler) { 1799 MetadataAnnotation ensureResolved(Compiler compiler) {
1792 if (resolutionState == STATE_NOT_STARTED) { 1800 if (resolutionState == STATE_NOT_STARTED) {
1793 compiler.resolver.resolveMetadataAnnotation(this); 1801 compiler.resolver.resolveMetadataAnnotation(this);
1794 } 1802 }
1795 return this; 1803 return this;
1796 } 1804 }
1797 1805
1798 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 1806 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1799 } 1807 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698