Chromium Code Reviews| 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 | 8 import '../common/names.dart' show |
| 9 Selectors; | 9 Selectors; |
| 10 import '../common/resolution.dart' show | 10 import '../common/resolution.dart' show |
| (...skipping 3995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4006 // [constructor] might be the implementation element | 4006 // [constructor] might be the implementation element |
| 4007 // and only declaration elements may be registered. | 4007 // and only declaration elements may be registered. |
| 4008 registry.registerStaticUse( | 4008 registry.registerStaticUse( |
| 4009 new StaticUse.constructorInvoke( | 4009 new StaticUse.constructorInvoke( |
| 4010 constructor.declaration, callStructure)); | 4010 constructor.declaration, callStructure)); |
| 4011 // TODO(johniwinther): Avoid registration of `type` in face of redirecting | 4011 // TODO(johniwinther): Avoid registration of `type` in face of redirecting |
| 4012 // factory constructors. | 4012 // factory constructors. |
| 4013 registry.registerTypeUse(new TypeUse.instantiation(type)); | 4013 registry.registerTypeUse(new TypeUse.instantiation(type)); |
| 4014 } | 4014 } |
| 4015 | 4015 |
| 4016 ResolutionResult resolutionResult = const NoneResult(); | |
| 4016 if (node.isConst) { | 4017 if (node.isConst) { |
| 4017 bool isValidAsConstant = !isInvalid && constructor.isConst; | 4018 bool isValidAsConstant = !isInvalid && constructor.isConst; |
| 4018 | 4019 |
| 4019 if (constructor == compiler.symbolConstructor) { | 4020 if (constructor == compiler.symbolConstructor) { |
| 4020 Node argumentNode = node.send.arguments.head; | 4021 Node argumentNode = node.send.arguments.head; |
| 4021 ConstantExpression constant = | 4022 ConstantExpression constant = |
| 4022 compiler.resolver.constantCompiler.compileNode( | 4023 compiler.resolver.constantCompiler.compileNode( |
| 4023 argumentNode, registry.mapping); | 4024 argumentNode, registry.mapping); |
| 4024 ConstantValue name = compiler.constants.getConstantValue(constant); | 4025 ConstantValue name = compiler.constants.getConstantValue(constant); |
| 4025 if (!name.isString) { | 4026 if (!name.isString) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 4046 node.send.selector, | 4047 node.send.selector, |
| 4047 MessageKind.TYPE_VARIABLE_IN_CONSTANT); | 4048 MessageKind.TYPE_VARIABLE_IN_CONSTANT); |
| 4048 isValidAsConstant = false; | 4049 isValidAsConstant = false; |
| 4049 isInvalid = true; | 4050 isInvalid = true; |
| 4050 } | 4051 } |
| 4051 | 4052 |
| 4052 if (result.isDeferred) { | 4053 if (result.isDeferred) { |
| 4053 isValidAsConstant = false; | 4054 isValidAsConstant = false; |
| 4054 } | 4055 } |
| 4055 | 4056 |
| 4057 // Callback hook for when the compile-time constant evaluator has | |
| 4058 // analyzed the constant. | |
| 4059 // TODO(johnniwinther): Remove this when all constants are computed | |
| 4060 // in resolution. | |
| 4061 Function onAnalyzed; | |
| 4056 if (isValidAsConstant && | 4062 if (isValidAsConstant && |
| 4057 argumentsResult.isValidAsConstant && | 4063 argumentsResult.isValidAsConstant && |
| 4058 // TODO(johnniwinther): Remove this when all constants are computed | 4064 // TODO(johnniwinther): Remove this when all constants are computed |
| 4059 // in resolution. | 4065 // in resolution. |
| 4060 !constructor.isFromEnvironmentConstructor) { | 4066 !constructor.isFromEnvironmentConstructor) { |
| 4061 CallStructure callStructure = argumentsResult.callStructure; | 4067 CallStructure callStructure = argumentsResult.callStructure; |
| 4062 List<ConstantExpression> arguments = argumentsResult.constantArguments; | 4068 List<ConstantExpression> arguments = argumentsResult.constantArguments; |
| 4063 | 4069 |
| 4064 ConstructedConstantExpression constant = | 4070 ConstructedConstantExpression constant = |
| 4065 new ConstructedConstantExpression( | 4071 new ConstructedConstantExpression( |
| 4066 type, | 4072 type, |
| 4067 constructor, | 4073 constructor, |
| 4068 callStructure, | 4074 callStructure, |
| 4069 arguments); | 4075 arguments); |
| 4070 registry.registerNewStructure(node, | 4076 registry.registerNewStructure(node, |
| 4071 new ConstInvokeStructure(ConstantInvokeKind.CONSTRUCTED, constant)); | 4077 new ConstInvokeStructure(ConstantInvokeKind.CONSTRUCTED, constant)); |
| 4072 return new ConstantResult(node, constant); | 4078 resolutionResult = new ConstantResult(node, constant); |
| 4073 } else if (isInvalid) { | 4079 } else if (isInvalid) { |
| 4074 // Known to be non-constant. | 4080 // Known to be non-constant. |
| 4075 kind == ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR; | 4081 kind == ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR; |
| 4076 registry.registerNewStructure(node, | 4082 registry.registerNewStructure(node, |
| 4077 new NewInvokeStructure( | 4083 new NewInvokeStructure( |
| 4078 new ConstructorAccessSemantics(kind, constructor, type), | 4084 new ConstructorAccessSemantics(kind, constructor, type), |
| 4079 selector)); | 4085 selector)); |
| 4080 } else { | 4086 } else { |
| 4081 // Might be valid but we don't know for sure. The compile-time constant | 4087 // Might be valid but we don't know for sure. The compile-time constant |
| 4082 // evaluator will compute the actual constant as a deferred action. | 4088 // evaluator will compute the actual constant as a deferred action. |
| 4083 registry.registerNewStructure(node, | 4089 LateConstInvokeStructure structure = |
| 4084 new LateConstInvokeStructure(registry.mapping)); | 4090 new LateConstInvokeStructure(registry.mapping); |
| 4091 registry.registerNewStructure(node, structure); | |
|
Siggi Cherem (dart-lang)
2016/04/08 16:10:45
do we need to register it if we are replacing it l
Johnni Winther
2016/04/11 07:40:45
I'm not sure. Adding a TODO for trying in a follow
| |
| 4092 onAnalyzed = () { | |
| 4093 registry.registerNewStructure(node, structure.resolve(node)); | |
| 4094 }; | |
| 4085 } | 4095 } |
| 4086 | 4096 |
| 4097 analyzeConstantDeferred(node, onAnalyzed: onAnalyzed); | |
| 4087 } else { | 4098 } else { |
| 4088 // Not constant. | 4099 // Not constant. |
| 4089 if (constructor == compiler.symbolConstructor && | 4100 if (constructor == compiler.symbolConstructor && |
| 4090 !compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(enclosingElement)) { | 4101 !compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(enclosingElement)) { |
| 4091 reporter.reportHintMessage( | 4102 reporter.reportHintMessage( |
| 4092 node.newToken, MessageKind.NON_CONST_BLOAT, | 4103 node.newToken, MessageKind.NON_CONST_BLOAT, |
| 4093 {'name': coreClasses.symbolClass.name}); | 4104 {'name': coreClasses.symbolClass.name}); |
| 4094 } | 4105 } |
| 4095 registry.registerNewStructure(node, | 4106 registry.registerNewStructure(node, |
| 4096 new NewInvokeStructure( | 4107 new NewInvokeStructure( |
| 4097 new ConstructorAccessSemantics(kind, constructor, type), | 4108 new ConstructorAccessSemantics(kind, constructor, type), |
| 4098 selector)); | 4109 selector)); |
| 4099 } | 4110 } |
| 4100 | 4111 |
| 4101 return const NoneResult(); | 4112 return resolutionResult; |
| 4102 } | 4113 } |
| 4103 | 4114 |
| 4104 void checkConstMapKeysDontOverrideEquals(Spannable spannable, | 4115 void checkConstMapKeysDontOverrideEquals(Spannable spannable, |
| 4105 MapConstantValue map) { | 4116 MapConstantValue map) { |
| 4106 for (ConstantValue key in map.keys) { | 4117 for (ConstantValue key in map.keys) { |
| 4107 if (!key.isObject) continue; | 4118 if (!key.isObject) continue; |
| 4108 ObjectConstantValue objectConstant = key; | 4119 ObjectConstantValue objectConstant = key; |
| 4109 DartType keyType = objectConstant.type; | 4120 DartType keyType = objectConstant.type; |
| 4110 ClassElement cls = keyType.element; | 4121 ClassElement cls = keyType.element; |
| 4111 if (cls == coreClasses.stringClass) continue; | 4122 if (cls == coreClasses.stringClass) continue; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4128 assert(invariant(node, compiler.compilationFailed)); | 4139 assert(invariant(node, compiler.compilationFailed)); |
| 4129 return; | 4140 return; |
| 4130 } | 4141 } |
| 4131 | 4142 |
| 4132 ConstantValue value = compiler.constants.getConstantValue(constant); | 4143 ConstantValue value = compiler.constants.getConstantValue(constant); |
| 4133 if (value.isMap) { | 4144 if (value.isMap) { |
| 4134 checkConstMapKeysDontOverrideEquals(node, value); | 4145 checkConstMapKeysDontOverrideEquals(node, value); |
| 4135 } | 4146 } |
| 4136 } | 4147 } |
| 4137 | 4148 |
| 4138 void analyzeConstantDeferred(Node node, {bool enforceConst: true}) { | 4149 void analyzeConstantDeferred(Node node, |
| 4150 {bool enforceConst: true, | |
| 4151 void onAnalyzed()}) { | |
|
Siggi Cherem (dart-lang)
2016/04/08 16:10:45
... eventually we should consider using futures in
Johnni Winther
2016/04/11 07:40:45
Acknowledged.
| |
| 4139 addDeferredAction(enclosingElement, () { | 4152 addDeferredAction(enclosingElement, () { |
| 4140 analyzeConstant(node, enforceConst: enforceConst); | 4153 analyzeConstant(node, enforceConst: enforceConst); |
| 4154 if (onAnalyzed != null) { | |
| 4155 onAnalyzed(); | |
| 4156 } | |
| 4141 }); | 4157 }); |
| 4142 } | 4158 } |
| 4143 | 4159 |
| 4144 bool validateSymbol(Node node, String name, {bool reportError: true}) { | 4160 bool validateSymbol(Node node, String name, {bool reportError: true}) { |
| 4145 if (name.isEmpty) return true; | 4161 if (name.isEmpty) return true; |
| 4146 if (name.startsWith('_')) { | 4162 if (name.startsWith('_')) { |
| 4147 if (reportError) { | 4163 if (reportError) { |
| 4148 reporter.reportErrorMessage( | 4164 reporter.reportErrorMessage( |
| 4149 node, MessageKind.PRIVATE_IDENTIFIER, {'value': name}); | 4165 node, MessageKind.PRIVATE_IDENTIFIER, {'value': name}); |
| 4150 } | 4166 } |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4878 } | 4894 } |
| 4879 return const NoneResult(); | 4895 return const NoneResult(); |
| 4880 } | 4896 } |
| 4881 } | 4897 } |
| 4882 | 4898 |
| 4883 /// Looks up [name] in [scope] and unwraps the result. | 4899 /// Looks up [name] in [scope] and unwraps the result. |
| 4884 Element lookupInScope(DiagnosticReporter reporter, Node node, | 4900 Element lookupInScope(DiagnosticReporter reporter, Node node, |
| 4885 Scope scope, String name) { | 4901 Scope scope, String name) { |
| 4886 return Elements.unwrap(scope.lookup(name), reporter, node); | 4902 return Elements.unwrap(scope.lookup(name), reporter, node); |
| 4887 } | 4903 } |
| OLD | NEW |