OLD | NEW |
---|---|
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 part of resolution; | 5 part of resolution; |
6 | 6 |
7 abstract class TreeElements { | 7 abstract class TreeElements { |
8 Element get currentElement; | 8 Element get currentElement; |
9 Setlet<Node> get superUses; | 9 Setlet<Node> get superUses; |
10 | 10 |
(...skipping 3080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3091 } else if (isMirrorsUsedConstant) { | 3091 } else if (isMirrorsUsedConstant) { |
3092 compiler.mirrorUsageAnalyzerTask.validate(node, mapping); | 3092 compiler.mirrorUsageAnalyzerTask.validate(node, mapping); |
3093 } | 3093 } |
3094 if (node.isConst()) { | 3094 if (node.isConst()) { |
3095 analyzeConstant(node); | 3095 analyzeConstant(node); |
3096 } | 3096 } |
3097 | 3097 |
3098 return null; | 3098 return null; |
3099 } | 3099 } |
3100 | 3100 |
3101 void checkConstMapKeysDontOverrideEquals(Spannable spannable, | |
3102 MapConstant map) { | |
3103 List<Constant> keys = map.keys.entries; | |
karlklose
2014/03/03 08:58:45
You can inline `keys`.
floitsch
2014/03/03 09:52:32
Done.
| |
3104 for (Constant key in keys) { | |
3105 if (!key.isObject()) continue; | |
3106 ObjectConstant objectConstant = key; | |
3107 DartType keyType = objectConstant.type; | |
3108 ClassElement cls = keyType.element; | |
3109 if (cls == compiler.stringClass) continue; | |
3110 Element equals = cls.lookupMember('=='); | |
3111 if (equals.getEnclosingClass() != compiler.objectClass) { | |
3112 compiler.reportError(spannable, | |
3113 MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS, | |
3114 {'type': keyType}); | |
3115 } | |
3116 } | |
3117 } | |
3118 | |
3101 void analyzeConstant(Node node, {bool isConst: true}) { | 3119 void analyzeConstant(Node node, {bool isConst: true}) { |
3102 addDeferredAction(enclosingElement, () { | 3120 addDeferredAction(enclosingElement, () { |
3103 Constant constant = compiler.constantHandler.compileNodeWithDefinitions( | 3121 Constant constant = compiler.constantHandler.compileNodeWithDefinitions( |
3104 node, mapping, isConst: isConst); | 3122 node, mapping, isConst: isConst); |
3105 | 3123 |
3124 if (isConst && constant != null && constant.isMap()) { | |
3125 checkConstMapKeysDontOverrideEquals(node, constant); | |
3126 } | |
3127 | |
3106 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names | 3128 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names |
3107 // a class that will be instantiated outside the program by attaching a | 3129 // a class that will be instantiated outside the program by attaching a |
3108 // native class dispatch record referencing the interceptor. | 3130 // native class dispatch record referencing the interceptor. |
3109 if (argumentsToJsInterceptorConstant != null && | 3131 if (argumentsToJsInterceptorConstant != null && |
3110 argumentsToJsInterceptorConstant.contains(node)) { | 3132 argumentsToJsInterceptorConstant.contains(node)) { |
3111 if (constant.isType()) { | 3133 if (constant.isType()) { |
3112 TypeConstant typeConstant = constant; | 3134 TypeConstant typeConstant = constant; |
3113 if (typeConstant.representedType is InterfaceType) { | 3135 if (typeConstant.representedType is InterfaceType) { |
3114 world.registerInstantiatedType(typeConstant.representedType, | 3136 world.registerInstantiatedType(typeConstant.representedType, |
3115 mapping); | 3137 mapping); |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4523 return finishConstructorReference(visit(expression), | 4545 return finishConstructorReference(visit(expression), |
4524 expression, expression); | 4546 expression, expression); |
4525 } | 4547 } |
4526 } | 4548 } |
4527 | 4549 |
4528 /// Looks up [name] in [scope] and unwraps the result. | 4550 /// Looks up [name] in [scope] and unwraps the result. |
4529 Element lookupInScope(Compiler compiler, Node node, | 4551 Element lookupInScope(Compiler compiler, Node node, |
4530 Scope scope, String name) { | 4552 Scope scope, String name) { |
4531 return Elements.unwrap(scope.lookup(name), compiler, node); | 4553 return Elements.unwrap(scope.lookup(name), compiler, node); |
4532 } | 4554 } |
OLD | NEW |