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

Unified Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 22909056: Support general expressions as keys in literal maps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/constants.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
diff --git a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
index f9339f03d14b769e54198083f3a195aaa8f06ce0..154f5b52546468d7e233f122686fc970ede2aff6 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -386,46 +386,53 @@ class CompileTimeConstantEvaluator extends Visitor {
if (!node.isConst()) {
return signalNotCompileTimeConstant(node);
}
- List<StringConstant> keys = <StringConstant>[];
- Map<StringConstant, Constant> map = new Map<StringConstant, Constant>();
+ List<Constant> keys = <Constant>[];
+ Map<Constant, Constant> map = new Map<Constant, Constant>();
for (Link<Node> link = node.entries.nodes;
!link.isEmpty;
link = link.tail) {
LiteralMapEntry entry = link.head;
Constant key = evaluateConstant(entry.key);
- if (!key.isString() || entry.key.asStringNode() == null) {
- compiler.reportFatalError(
- entry.key, MessageKind.KEY_NOT_A_STRING_LITERAL);
- }
- StringConstant keyConstant = key;
if (!map.containsKey(key)) keys.add(key);
map[key] = evaluateConstant(entry.value);
}
- List<Constant> values = <Constant>[];
+
+ bool onlyStringKeys = true;
Constant protoValue = null;
- for (StringConstant key in keys) {
- if (key.value == MapConstant.PROTO_PROPERTY) {
- protoValue = map[key];
+ for (var key in keys) {
+ if (key.isString()) {
+ if (key.value == MapConstant.PROTO_PROPERTY) {
+ protoValue = map[key];
+ }
} else {
- values.add(map[key]);
+ onlyStringKeys = false;
+ // Don't handle __proto__ values specially in the general map case.
+ protoValue = null;
+ break;
}
}
+
bool hasProtoKey = (protoValue != null);
+ List<Constant> values = map.values.toList();
InterfaceType sourceType = elements.getType(node);
Link<DartType> arguments =
new Link<DartType>.fromList([compiler.stringClass.rawType]);
DartType keysType = new InterfaceType(compiler.listClass, arguments);
ListConstant keysList = new ListConstant(keysType, keys);
- handler.registerCompileTimeConstant(keysList, elements);
- SourceString className = hasProtoKey
- ? MapConstant.DART_PROTO_CLASS
- : MapConstant.DART_CLASS;
+ if (onlyStringKeys) {
+ handler.registerCompileTimeConstant(keysList, elements);
+ }
+ SourceString className = onlyStringKeys
+ ? (hasProtoKey ? MapConstant.DART_PROTO_CLASS
+ : MapConstant.DART_STRING_CLASS)
+ : MapConstant.DART_GENERAL_CLASS;
ClassElement classElement = compiler.jsHelperLibrary.find(className);
classElement.ensureResolved(compiler);
- Link<DartType> typeArgument = sourceType.typeArguments.tail;
+ Link<DartType> typeArgument = sourceType.typeArguments;
InterfaceType type = new InterfaceType(classElement, typeArgument);
handler.registerInstantiatedType(type, elements);
- Constant constant = new MapConstant(type, keysList, values, protoValue);
+ Constant constant =
+ new MapConstant(type, keysList, values, protoValue, onlyStringKeys);
handler.registerCompileTimeConstant(constant, elements);
return constant;
}
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698