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

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: 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
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 4d43a2a5adee683a69b91f23109732edd379db99..89fd7186e89a17c558260564612f986fc80c43f9 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -386,27 +386,27 @@ 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);
}
+ bool hasNonStringKey = false;
ngeoffray 2013/09/13 07:30:15 Negating names are confusing. How about 'onlyStrin
Johnni Winther 2013/09/18 12:37:21 Done.
List<Constant> values = <Constant>[];
Constant protoValue = null;
- for (StringConstant key in keys) {
- if (key.value == MapConstant.PROTO_PROPERTY) {
+ for (Constant key in keys) {
+ if (key.isString() &&
+ (key as dynamic).value == MapConstant.PROTO_PROPERTY) {
ngeoffray 2013/09/13 07:30:15 I'd prefer avoiding this as, and untype 'key'.
Johnni Winther 2013/09/18 12:37:21 Done.
protoValue = map[key];
} else {
+ if (!key.isString()) {
ngeoffray 2013/09/13 07:30:15 Checking twice here. I suggest: if (key.isString()
Johnni Winther 2013/09/18 12:37:21 Completely rewritten.
+ hasNonStringKey = true;
+ }
values.add(map[key]);
}
}
@@ -416,16 +416,20 @@ class CompileTimeConstantEvaluator extends Visitor {
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 (!hasNonStringKey) {
+ handler.registerCompileTimeConstant(keysList, elements);
+ }
+ SourceString className = hasNonStringKey
+ ? MapConstant.DART_GENERAL_CLASS
+ : (hasProtoKey ? MapConstant.DART_PROTO_CLASS
+ : MapConstant.DART_STRING_CLASS);
ClassElement classElement = compiler.jsHelperLibrary.find(className);
classElement.ensureResolved(compiler);
- Link<DartType> typeArgument = sourceType.typeArguments.tail;
+ Link<DartType> typeArgument = sourceType.typeArguments;
ngeoffray 2013/09/13 07:30:15 What is this change?
Johnni Winther 2013/09/18 12:37:21 ConstantMap<V> implements Map<String, V> (and frie
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, hasNonStringKey);
handler.registerCompileTimeConstant(constant, elements);
return constant;
}

Powered by Google App Engine
This is Rietveld 408576698