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 library dart2js.resolution.members; | 5 library dart2js.resolution.members; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/names.dart' show Selectors; | 8 import '../common/names.dart' show Selectors; |
9 import '../common/resolution.dart' show Feature; | 9 import '../common/resolution.dart' show Feature; |
10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1989 registry.useElement(node, element); | 1989 registry.useElement(node, element); |
1990 registry.registerTypeLiteral(node, type); | 1990 registry.registerTypeLiteral(node, type); |
1991 | 1991 |
1992 if (node.isCall) { | 1992 if (node.isCall) { |
1993 CallStructure callStructure = | 1993 CallStructure callStructure = |
1994 resolveArguments(node.argumentsNode).callStructure; | 1994 resolveArguments(node.argumentsNode).callStructure; |
1995 Selector selector = callStructure.callSelector; | 1995 Selector selector = callStructure.callSelector; |
1996 // TODO(23998): Remove this when all information goes through | 1996 // TODO(23998): Remove this when all information goes through |
1997 // the [SendStructure]. | 1997 // the [SendStructure]. |
1998 registry.setSelector(node, selector); | 1998 registry.setSelector(node, selector); |
1999 | 1999 |
2000 // The node itself is not a constant but we register the selector (the | |
2001 // identifier that refers to the class/typedef) as a constant. | |
2002 registry.useElement(node.selector, element); | 2000 registry.useElement(node.selector, element); |
2003 analyzeConstantDeferred(node.selector, enforceConst: false); | 2001 analyzeConstantDeferred(node.selector); |
2004 | 2002 |
2005 registry.registerSendStructure( | 2003 registry.registerSendStructure( |
2006 node, new InvokeStructure(semantics, selector)); | 2004 node, new InvokeStructure(semantics, selector)); |
2007 return const NoneResult(); | 2005 return const NoneResult(); |
2008 } else { | 2006 } else { |
2009 analyzeConstantDeferred(node, enforceConst: false); | 2007 analyzeConstantDeferred(node); |
2010 | 2008 |
2011 registry.setConstant(node, semantics.constant); | 2009 registry.setConstant(node, semantics.constant); |
2012 registry.registerSendStructure(node, new GetStructure(semantics)); | 2010 registry.registerSendStructure(node, new GetStructure(semantics)); |
2013 return new ConstantResult(node, semantics.constant); | 2011 return new ConstantResult(node, semantics.constant); |
2014 } | 2012 } |
2015 } | 2013 } |
2016 | 2014 |
2017 /// Handle access to a constant type literal of [type]. | 2015 /// Handle access to a constant type literal of [type]. |
2018 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the | 2016 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the |
2019 // the [GetStructure]. | 2017 // the [GetStructure]. |
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3993 ClassElement cls = keyType.element; | 3991 ClassElement cls = keyType.element; |
3994 if (cls == coreClasses.stringClass) continue; | 3992 if (cls == coreClasses.stringClass) continue; |
3995 Element equals = cls.lookupMember('=='); | 3993 Element equals = cls.lookupMember('=='); |
3996 if (equals.enclosingClass != coreClasses.objectClass) { | 3994 if (equals.enclosingClass != coreClasses.objectClass) { |
3997 reporter.reportErrorMessage(spannable, | 3995 reporter.reportErrorMessage(spannable, |
3998 MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS, {'type': keyType}); | 3996 MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS, {'type': keyType}); |
3999 } | 3997 } |
4000 } | 3998 } |
4001 } | 3999 } |
4002 | 4000 |
4003 void analyzeConstant(Node node, {enforceConst: true}) { | 4001 void analyzeConstant(Node node) { |
4004 ConstantExpression constant = compiler.resolver.constantCompiler | 4002 ConstantExpression constant = |
4005 .compileNode(node, registry.mapping, enforceConst: enforceConst); | 4003 compiler.resolver.constantCompiler.compileNode(node, registry.mapping); |
4006 | 4004 |
4007 if (constant == null) { | 4005 if (constant == null) { |
4008 assert(invariant(node, compiler.compilationFailed)); | 4006 assert(invariant(node, compiler.compilationFailed)); |
4009 return; | 4007 return; |
4010 } | 4008 } |
4011 | 4009 |
4012 ConstantValue value = compiler.constants.getConstantValue(constant); | 4010 ConstantValue value = compiler.constants.getConstantValue(constant); |
4013 if (value.isMap) { | 4011 if (value.isMap) { |
4014 checkConstMapKeysDontOverrideEquals(node, value); | 4012 checkConstMapKeysDontOverrideEquals(node, value); |
4015 } | 4013 } |
4016 } | 4014 } |
4017 | 4015 |
4018 void analyzeConstantDeferred(Node node, | 4016 void analyzeConstantDeferred(Node node, {void onAnalyzed()}) { |
4019 {bool enforceConst: true, void onAnalyzed()}) { | |
4020 addDeferredAction(enclosingElement, () { | 4017 addDeferredAction(enclosingElement, () { |
4021 analyzeConstant(node, enforceConst: enforceConst); | 4018 analyzeConstant(node); |
4022 if (onAnalyzed != null) { | 4019 if (onAnalyzed != null) { |
4023 onAnalyzed(); | 4020 onAnalyzed(); |
4024 } | 4021 } |
4025 }); | 4022 }); |
4026 } | 4023 } |
4027 | 4024 |
4028 bool validateSymbol(Node node, String name, {bool reportError: true}) { | 4025 bool validateSymbol(Node node, String name, {bool reportError: true}) { |
4029 if (name.isEmpty) return true; | 4026 if (name.isEmpty) return true; |
4030 if (name.startsWith('_')) { | 4027 if (name.startsWith('_')) { |
4031 if (reportError) { | 4028 if (reportError) { |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4726 } | 4723 } |
4727 return const NoneResult(); | 4724 return const NoneResult(); |
4728 } | 4725 } |
4729 } | 4726 } |
4730 | 4727 |
4731 /// Looks up [name] in [scope] and unwraps the result. | 4728 /// Looks up [name] in [scope] and unwraps the result. |
4732 Element lookupInScope( | 4729 Element lookupInScope( |
4733 DiagnosticReporter reporter, Node node, Scope scope, String name) { | 4730 DiagnosticReporter reporter, Node node, Scope scope, String name) { |
4734 return Elements.unwrap(scope.lookup(name), reporter, node); | 4731 return Elements.unwrap(scope.lookup(name), reporter, node); |
4735 } | 4732 } |
OLD | NEW |