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

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

Issue 10905211: Clean up operator names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added test Created 8 years, 1 month 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' as api_e; 10 import '../../compiler.dart' as api_e;
(...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 return isLocal(element); 1795 return isLocal(element);
1796 } 1796 }
1797 1797
1798 static SourceString constructConstructorName(SourceString receiver, 1798 static SourceString constructConstructorName(SourceString receiver,
1799 SourceString selector) { 1799 SourceString selector) {
1800 String r = receiver.slowToString(); 1800 String r = receiver.slowToString();
1801 String s = selector.slowToString(); 1801 String s = selector.slowToString();
1802 return new SourceString('$r\$$s'); 1802 return new SourceString('$r\$$s');
1803 } 1803 }
1804 1804
1805 static const SourceString OPERATOR_EQUALS = 1805 /**
1806 const SourceString(r'operator$eq'); 1806 * Map an operator-name to a valid Dart identifier.
1807 *
1808 * For non-operator names, this metod just returns its input.
ngeoffray 2012/11/13 11:56:19 Should this method be named mapPotentialOperatorNa
ahe 2012/11/15 07:00:33 This method really maps an arbitrary method name t
ngeoffray 2012/11/15 11:15:58 I find the use of operator in the name of this met
1809 *
1810 * The results returned from this method are guaranteed to be valid
1811 * JavaScript identifers, except it may include reserved words for
1812 * non-operator names.
1813 */
1814 static SourceString operatorNameToIdentifier(SourceString name) {
1815 if (name == null) return null;
1816 String value = name.stringValue;
1817 // A valid Dart identifier cannot start with a digit.
1818 // Fortunately, operators are always enclosed in a class which
1819 // means that the resulting closure name will not start with a
ngeoffray 2012/11/13 11:56:19 what closure? Do you mean member?
ahe 2012/11/15 07:00:33 This comment is a cut-and-paste error. I have rem
1820 // digit.
1821 if (value == null) {
1822 return name;
1823 } else if (identical(value, '==')) {
1824 return const SourceString(r'operator$eq');
1825 } else if (identical(value, '~')) {
1826 return const SourceString(r'operator$not');
1827 } else if (identical(value, '[]')) {
1828 return const SourceString(r'operator$index');
1829 } else if (identical(value, '[]=')) {
1830 return const SourceString(r'oprator$indexSet');
1831 } else if (identical(value, '*')) {
1832 return const SourceString(r'operator$mul');
1833 } else if (identical(value, '/')) {
1834 return const SourceString(r'operator$div');
1835 } else if (identical(value, '%')) {
1836 return const SourceString(r'operator$mod');
1837 } else if (identical(value, '~/')) {
1838 return const SourceString(r'operator$tdiv');
1839 } else if (identical(value, '+')) {
1840 return const SourceString(r'operator$add');
1841 } else if (identical(value, '<<')) {
1842 return const SourceString(r'operator$shl');
1843 } else if (identical(value, '>>')) {
1844 return const SourceString(r'operator$shr');
1845 } else if (identical(value, '>=')) {
1846 return const SourceString(r'operator$ge');
1847 } else if (identical(value, '>')) {
1848 return const SourceString(r'operator$gt');
1849 } else if (identical(value, '<=')) {
1850 return const SourceString(r'operator$le');
1851 } else if (identical(value, '<')) {
1852 return const SourceString(r'operator$lt');
1853 } else if (identical(value, '&')) {
1854 return const SourceString(r'operator$and');
1855 } else if (identical(value, '^')) {
1856 return const SourceString(r'operator$xor');
1857 } else if (identical(value, '|')) {
1858 return const SourceString(r'operator$or');
1859 } else if (identical(value, '-')) {
1860 return const SourceString(r'operator$sub');
1861 } else if (identical(value, 'unary-')) {
1862 return const SourceString(r'operator$negate');
1863 } else {
1864 return name;
1865 }
1866 }
1807 1867
1808 static SourceString constructOperatorName(SourceString selector, 1868 static SourceString constructOperatorName(SourceString op, bool isUnary) {
1809 bool isUnary) { 1869 String value = op.stringValue;
1810 String str = selector.stringValue; 1870 if ((value === '==') ||
1811 if (identical(str, '==') || identical(str, '!=')) return OPERATOR_EQUALS; 1871 (value === '~') ||
1812 1872 (value === '[]') ||
1813 if (identical(str, '~')) { 1873 (value === '[]=') ||
1814 str = 'not'; 1874 (value === '*') ||
1815 } else if (identical(str, '-') && isUnary) { 1875 (value === '/') ||
1816 // TODO(ahe): Return something like 'unary -'. 1876 (value === '%') ||
1817 return const SourceString('negate'); 1877 (value === '~/') ||
1818 } else if (identical(str, '[]')) { 1878 (value === '+') ||
1819 str = 'index'; 1879 (value === '<<') ||
1820 } else if (identical(str, '[]=')) { 1880 (value === '>>>') ||
1821 str = 'indexSet'; 1881 (value === '>>') ||
1822 } else if (identical(str, '*') || identical(str, '*=')) { 1882 (value === '>=') ||
1823 str = 'mul'; 1883 (value === '>') ||
1824 } else if (identical(str, '/') || identical(str, '/=')) { 1884 (value === '<=') ||
1825 str = 'div'; 1885 (value === '<') ||
1826 } else if (identical(str, '%') || identical(str, '%=')) { 1886 (value === '&') ||
1827 str = 'mod'; 1887 (value === '^') ||
1828 } else if (identical(str, '~/') || identical(str, '~/=')) { 1888 (value === '|')) {
1829 str = 'tdiv'; 1889 return op;
1830 } else if (identical(str, '+') || identical(str, '+=')) { 1890 } else if (value === '-') {
1831 str = 'add'; 1891 return isUnary ? const SourceString('unary-') : op;
1832 } else if (identical(str, '-') || identical(str, '-=')) {
1833 str = 'sub';
1834 } else if (identical(str, '<<') || identical(str, '<<=')) {
1835 str = 'shl';
1836 } else if (identical(str, '>>') || identical(str, '>>=')) {
1837 str = 'shr';
1838 } else if (identical(str, '>=')) {
1839 str = 'ge';
1840 } else if (identical(str, '>')) {
1841 str = 'gt';
1842 } else if (identical(str, '<=')) {
1843 str = 'le';
1844 } else if (identical(str, '<')) {
1845 str = 'lt';
1846 } else if (identical(str, '&') || identical(str, '&=')) {
1847 str = 'and';
1848 } else if (identical(str, '^') || identical(str, '^=')) {
1849 str = 'xor';
1850 } else if (identical(str, '|') || identical(str, '|=')) {
1851 str = 'or';
1852 } else if (selector == const SourceString('negate')) {
1853 // TODO(ahe): Remove this case: Legacy support for pre-0.11 spec.
1854 return selector;
1855 } else if (identical(str, '?')) {
1856 return selector;
1857 } else { 1892 } else {
1858 throw new Exception('Unhandled selector: ${selector.slowToString()}'); 1893 throw 'Unhandled operator: ${op.slowToString()}';
1859 } 1894 }
1860 return new SourceString('operator\$$str');
1861 } 1895 }
1862 1896
1863 static SourceString mapToUserOperator(SourceString op) { 1897 static SourceString mapToUserOperator(SourceString op) {
1864 String value = op.stringValue; 1898 String value = op.stringValue;
1865 1899
1866 if (identical(value, '!=')) return const SourceString('=='); 1900 if (identical(value, '!=')) return const SourceString('==');
1867 if (identical(value, '*=')) return const SourceString('*'); 1901 if (identical(value, '*=')) return const SourceString('*');
1868 if (identical(value, '/=')) return const SourceString('/'); 1902 if (identical(value, '/=')) return const SourceString('/');
1869 if (identical(value, '%=')) return const SourceString('%'); 1903 if (identical(value, '%=')) return const SourceString('%');
1870 if (identical(value, '~/=')) return const SourceString('~/'); 1904 if (identical(value, '~/=')) return const SourceString('~/');
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 2043
2010 MetadataAnnotation ensureResolved(Compiler compiler) { 2044 MetadataAnnotation ensureResolved(Compiler compiler) {
2011 if (resolutionState == STATE_NOT_STARTED) { 2045 if (resolutionState == STATE_NOT_STARTED) {
2012 compiler.resolver.resolveMetadataAnnotation(this); 2046 compiler.resolver.resolveMetadataAnnotation(this);
2013 } 2047 }
2014 return this; 2048 return this;
2015 } 2049 }
2016 2050
2017 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 2051 String toString() => 'MetadataAnnotation($value, $resolutionState)';
2018 } 2052 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698