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

Side by Side Diff: pkg/compiler/lib/src/js_backend/namer.dart

Issue 2711183002: Store toString value in enum. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 js_backend.namer; 5 library js_backend.namer;
6 6
7 import 'dart:collection' show HashMap; 7 import 'dart:collection' show HashMap;
8 8
9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName;
10 10
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 } else { 1874 } else {
1875 // Using some bits from the keys hash tag groups the names Maps with the 1875 // Using some bits from the keys hash tag groups the names Maps with the
1876 // same structure. 1876 // same structure.
1877 add(getHashTag(constant.keyList, 2) + getHashTag(constant, 3)); 1877 add(getHashTag(constant.keyList, 2) + getHashTag(constant, 3));
1878 } 1878 }
1879 } 1879 }
1880 1880
1881 @override 1881 @override
1882 void visitConstructed(ConstructedConstantValue constant, [_]) { 1882 void visitConstructed(ConstructedConstantValue constant, [_]) {
1883 addRoot(constant.type.element.name); 1883 addRoot(constant.type.element.name);
1884
1885 // Recognize enum constants and only include the index.
1886 final Map<FieldEntity, ConstantValue> fieldMap = constant.fields;
1887 int size = fieldMap.length;
1888 if (size == 1 || size == 2) {
1889 FieldEntity indexField;
1890 for (FieldEntity field in fieldMap.keys) {
1891 String name = field.name;
1892 if (name == 'index') {
1893 indexField = field;
1894 } else if (name == '_name') {
1895 // Ingore _name field.
1896 } else {
1897 indexField = null;
1898 break;
1899 }
1900 }
1901 if (indexField != null) {
1902 _visit(constant.fields[indexField]);
1903 return;
1904 }
1905 }
1906
1884 // TODO(johnniwinther): This should be accessed from a codegen closed world. 1907 // TODO(johnniwinther): This should be accessed from a codegen closed world.
1885 codegenWorldBuilder.forEachInstanceField(constant.type.element, 1908 codegenWorldBuilder.forEachInstanceField(constant.type.element,
1886 (_, FieldElement field) { 1909 (_, FieldElement field) {
1887 if (failed) return; 1910 if (failed) return;
1888 _visit(constant.fields[field]); 1911 _visit(constant.fields[field]);
1889 }); 1912 });
1890 } 1913 }
1891 1914
1892 @override 1915 @override
1893 void visitType(TypeConstantValue constant, [_]) { 1916 void visitType(TypeConstantValue constant, [_]) {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 void addSuggestion(String original, String suggestion) { 2223 void addSuggestion(String original, String suggestion) {
2201 assert(!_suggestedNames.containsKey(original)); 2224 assert(!_suggestedNames.containsKey(original));
2202 _suggestedNames[original] = suggestion; 2225 _suggestedNames[original] = suggestion;
2203 } 2226 }
2204 2227
2205 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); 2228 bool hasSuggestion(String original) => _suggestedNames.containsKey(original);
2206 bool isSuggestion(String candidate) { 2229 bool isSuggestion(String candidate) {
2207 return _suggestedNames.containsValue(candidate); 2230 return _suggestedNames.containsValue(candidate);
2208 } 2231 }
2209 } 2232 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/parser/element_listener.dart » ('j') | pkg/compiler/lib/src/parser/element_listener.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698