| 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/names.dart' show |
| 8 Selectors; |
| 7 import '../compiler.dart' show | 9 import '../compiler.dart' show |
| 8 Compiler, | 10 Compiler, |
| 9 isPrivateName; | 11 isPrivateName; |
| 10 import '../constants/constructors.dart' show | 12 import '../constants/constructors.dart' show |
| 11 RedirectingFactoryConstantConstructor; | 13 RedirectingFactoryConstantConstructor; |
| 12 import '../constants/expressions.dart'; | 14 import '../constants/expressions.dart'; |
| 13 import '../constants/values.dart'; | 15 import '../constants/values.dart'; |
| 14 import '../core_types.dart'; | 16 import '../core_types.dart'; |
| 15 import '../dart_types.dart'; | 17 import '../dart_types.dart'; |
| 16 import '../diagnostics/invariant.dart' show | 18 import '../diagnostics/invariant.dart' show |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } | 413 } |
| 412 return new TypeResult(type); | 414 return new TypeResult(type); |
| 413 } | 415 } |
| 414 | 416 |
| 415 bool isNamedConstructor(Send node) => node.receiver != null; | 417 bool isNamedConstructor(Send node) => node.receiver != null; |
| 416 | 418 |
| 417 Selector getRedirectingThisOrSuperConstructorSelector(Send node) { | 419 Selector getRedirectingThisOrSuperConstructorSelector(Send node) { |
| 418 if (isNamedConstructor(node)) { | 420 if (isNamedConstructor(node)) { |
| 419 String constructorName = node.selector.asIdentifier().source; | 421 String constructorName = node.selector.asIdentifier().source; |
| 420 return new Selector.callConstructor( | 422 return new Selector.callConstructor( |
| 421 constructorName, | 423 new Name(constructorName, enclosingElement.library)); |
| 422 enclosingElement.library); | |
| 423 } else { | 424 } else { |
| 424 return new Selector.callDefaultConstructor(); | 425 return new Selector.callDefaultConstructor(); |
| 425 } | 426 } |
| 426 } | 427 } |
| 427 | 428 |
| 428 FunctionElement resolveConstructorRedirection(FunctionElementX constructor) { | 429 FunctionElement resolveConstructorRedirection(FunctionElementX constructor) { |
| 429 FunctionExpression node = constructor.parseNode(compiler); | 430 FunctionExpression node = constructor.parseNode(compiler); |
| 430 | 431 |
| 431 // A synthetic constructor does not have a node. | 432 // A synthetic constructor does not have a node. |
| 432 if (node == null) return null; | 433 if (node == null) return null; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 identical(string, '>>>')) { | 801 identical(string, '>>>')) { |
| 801 return null; | 802 return null; |
| 802 } | 803 } |
| 803 String op = source; | 804 String op = source; |
| 804 if (!isUserDefinableOperator(source)) { | 805 if (!isUserDefinableOperator(source)) { |
| 805 op = Elements.mapToUserOperatorOrNull(source); | 806 op = Elements.mapToUserOperatorOrNull(source); |
| 806 } | 807 } |
| 807 if (op == null) { | 808 if (op == null) { |
| 808 // Unsupported operator. An error has been reported during parsing. | 809 // Unsupported operator. An error has been reported during parsing. |
| 809 return new Selector.call( | 810 return new Selector.call( |
| 810 source, library, node.argumentsNode.slowLength(), []); | 811 new Name(source, library), node.argumentsNode.slowLength(), []); |
| 811 } | 812 } |
| 812 return node.arguments.isEmpty | 813 return node.arguments.isEmpty |
| 813 ? new Selector.unaryOperator(op) | 814 ? new Selector.unaryOperator(op) |
| 814 : new Selector.binaryOperator(op); | 815 : new Selector.binaryOperator(op); |
| 815 } | 816 } |
| 816 | 817 |
| 817 Identifier identifier = node.selector.asIdentifier(); | 818 Identifier identifier = node.selector.asIdentifier(); |
| 818 if (node.isPropertyAccess) { | 819 if (node.isPropertyAccess) { |
| 819 assert(!isSet); | 820 assert(!isSet); |
| 820 return new Selector.getter(identifier.source, library); | 821 return new Selector.getter( |
| 822 new Name(identifier.source, library)); |
| 821 } else if (isSet) { | 823 } else if (isSet) { |
| 822 return new Selector.setter(identifier.source, library); | 824 return new Selector.setter( |
| 825 new Name(identifier.source, library, isSetter: true)); |
| 823 } | 826 } |
| 824 | 827 |
| 825 // Compute the arity and the list of named arguments. | 828 // Compute the arity and the list of named arguments. |
| 826 int arity = 0; | 829 int arity = 0; |
| 827 List<String> named = <String>[]; | 830 List<String> named = <String>[]; |
| 828 for (Link<Node> link = node.argumentsNode.nodes; | 831 for (Link<Node> link = node.argumentsNode.nodes; |
| 829 !link.isEmpty; | 832 !link.isEmpty; |
| 830 link = link.tail) { | 833 link = link.tail) { |
| 831 Expression argument = link.head; | 834 Expression argument = link.head; |
| 832 NamedArgument namedArgument = argument.asNamedArgument(); | 835 NamedArgument namedArgument = argument.asNamedArgument(); |
| 833 if (namedArgument != null) { | 836 if (namedArgument != null) { |
| 834 named.add(namedArgument.name.source); | 837 named.add(namedArgument.name.source); |
| 835 } | 838 } |
| 836 arity++; | 839 arity++; |
| 837 } | 840 } |
| 838 | 841 |
| 839 if (element != null && element.isConstructor) { | 842 if (element != null && element.isConstructor) { |
| 840 return new Selector.callConstructor( | 843 return new Selector.callConstructor( |
| 841 element.name, library, arity, named); | 844 new Name(element.name, library), arity, named); |
| 842 } | 845 } |
| 843 | 846 |
| 844 // If we're invoking a closure, we do not have an identifier. | 847 // If we're invoking a closure, we do not have an identifier. |
| 845 return (identifier == null) | 848 return (identifier == null) |
| 846 ? new Selector.callClosure(arity, named) | 849 ? new Selector.callClosure(arity, named) |
| 847 : new Selector.call(identifier.source, library, arity, named); | 850 : new Selector.call(new Name(identifier.source, library), arity, named); |
| 848 } | 851 } |
| 849 | 852 |
| 850 Selector resolveSelector(Send node, Element element) { | 853 Selector resolveSelector(Send node, Element element) { |
| 851 LibraryElement library = enclosingElement.library; | 854 LibraryElement library = enclosingElement.library; |
| 852 Selector selector = computeSendSelector(node, library, element); | 855 Selector selector = computeSendSelector(node, library, element); |
| 853 if (selector != null) registry.setSelector(node, selector); | 856 if (selector != null) registry.setSelector(node, selector); |
| 854 return selector; | 857 return selector; |
| 855 } | 858 } |
| 856 | 859 |
| 857 ArgumentsResult resolveArguments(NodeList list) { | 860 ArgumentsResult resolveArguments(NodeList list) { |
| (...skipping 3229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4087 elseResult.constant); | 4090 elseResult.constant); |
| 4088 registry.setConstant(node, constant); | 4091 registry.setConstant(node, constant); |
| 4089 return new ConstantResult(node, constant); | 4092 return new ConstantResult(node, constant); |
| 4090 } | 4093 } |
| 4091 return const NoneResult(); | 4094 return const NoneResult(); |
| 4092 } | 4095 } |
| 4093 | 4096 |
| 4094 ResolutionResult visitStringInterpolation(StringInterpolation node) { | 4097 ResolutionResult visitStringInterpolation(StringInterpolation node) { |
| 4095 registry.registerInstantiatedType(coreTypes.stringType); | 4098 registry.registerInstantiatedType(coreTypes.stringType); |
| 4096 registry.registerStringInterpolation(); | 4099 registry.registerStringInterpolation(); |
| 4097 registerImplicitInvocation('toString', 0); | 4100 registerImplicitInvocation(Selectors.toString_); |
| 4098 | 4101 |
| 4099 bool isValidAsConstant = true; | 4102 bool isValidAsConstant = true; |
| 4100 List<ConstantExpression> parts = <ConstantExpression>[]; | 4103 List<ConstantExpression> parts = <ConstantExpression>[]; |
| 4101 | 4104 |
| 4102 void resolvePart(Node subnode) { | 4105 void resolvePart(Node subnode) { |
| 4103 ResolutionResult result = visit(subnode); | 4106 ResolutionResult result = visit(subnode); |
| 4104 if (isValidAsConstant && result.isConstant) { | 4107 if (isValidAsConstant && result.isConstant) { |
| 4105 parts.add(result.constant); | 4108 parts.add(result.constant); |
| 4106 } else { | 4109 } else { |
| 4107 isValidAsConstant = false; | 4110 isValidAsConstant = false; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4170 if (!target.statement.isValidContinueTarget()) { | 4173 if (!target.statement.isValidContinueTarget()) { |
| 4171 error(node.target, MessageKind.INVALID_CONTINUE); | 4174 error(node.target, MessageKind.INVALID_CONTINUE); |
| 4172 } | 4175 } |
| 4173 label.setContinueTarget(); | 4176 label.setContinueTarget(); |
| 4174 registry.useLabel(node, label); | 4177 registry.useLabel(node, label); |
| 4175 } | 4178 } |
| 4176 registry.registerTargetOf(node, target); | 4179 registry.registerTargetOf(node, target); |
| 4177 return const NoneResult(); | 4180 return const NoneResult(); |
| 4178 } | 4181 } |
| 4179 | 4182 |
| 4180 registerImplicitInvocation(String name, int arity) { | 4183 registerImplicitInvocation(Selector selector) { |
| 4181 Selector selector = new Selector.call(name, null, arity); | |
| 4182 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); | 4184 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); |
| 4183 } | 4185 } |
| 4184 | 4186 |
| 4185 ResolutionResult visitAsyncForIn(AsyncForIn node) { | 4187 ResolutionResult visitAsyncForIn(AsyncForIn node) { |
| 4186 registry.registerAsyncForIn(node); | 4188 registry.registerAsyncForIn(node); |
| 4187 registry.setCurrentSelector(node, compiler.currentSelector); | 4189 registry.setCurrentSelector(node, Selectors.current); |
| 4188 registry.registerDynamicGetter( | 4190 registry.registerDynamicGetter( |
| 4189 new UniverseSelector(compiler.currentSelector, null)); | 4191 new UniverseSelector(Selectors.current, null)); |
| 4190 registry.setMoveNextSelector(node, compiler.moveNextSelector); | 4192 registry.setMoveNextSelector(node, Selectors.moveNext); |
| 4191 registry.registerDynamicInvocation( | 4193 registry.registerDynamicInvocation( |
| 4192 new UniverseSelector(compiler.moveNextSelector, null)); | 4194 new UniverseSelector(Selectors.moveNext, null)); |
| 4193 | 4195 |
| 4194 visit(node.expression); | 4196 visit(node.expression); |
| 4195 | 4197 |
| 4196 Scope blockScope = new BlockScope(scope); | 4198 Scope blockScope = new BlockScope(scope); |
| 4197 visitForInDeclaredIdentifierIn(node.declaredIdentifier, node, blockScope); | 4199 visitForInDeclaredIdentifierIn(node.declaredIdentifier, node, blockScope); |
| 4198 visitLoopBodyIn(node, node.body, blockScope); | 4200 visitLoopBodyIn(node, node.body, blockScope); |
| 4199 return const NoneResult(); | 4201 return const NoneResult(); |
| 4200 } | 4202 } |
| 4201 | 4203 |
| 4202 ResolutionResult visitSyncForIn(SyncForIn node) { | 4204 ResolutionResult visitSyncForIn(SyncForIn node) { |
| 4203 registry.registerSyncForIn(node); | 4205 registry.registerSyncForIn(node); |
| 4204 registry.setIteratorSelector(node, compiler.iteratorSelector); | 4206 registry.setIteratorSelector(node, Selectors.iterator); |
| 4205 registry.registerDynamicGetter( | 4207 registry.registerDynamicGetter( |
| 4206 new UniverseSelector(compiler.iteratorSelector, null)); | 4208 new UniverseSelector(Selectors.iterator, null)); |
| 4207 registry.setCurrentSelector(node, compiler.currentSelector); | 4209 registry.setCurrentSelector(node, Selectors.current); |
| 4208 registry.registerDynamicGetter( | 4210 registry.registerDynamicGetter( |
| 4209 new UniverseSelector(compiler.currentSelector, null)); | 4211 new UniverseSelector(Selectors.current, null)); |
| 4210 registry.setMoveNextSelector(node, compiler.moveNextSelector); | 4212 registry.setMoveNextSelector(node, Selectors.moveNext); |
| 4211 registry.registerDynamicInvocation( | 4213 registry.registerDynamicInvocation( |
| 4212 new UniverseSelector(compiler.moveNextSelector, null)); | 4214 new UniverseSelector(Selectors.moveNext, null)); |
| 4213 | 4215 |
| 4214 visit(node.expression); | 4216 visit(node.expression); |
| 4215 | 4217 |
| 4216 Scope blockScope = new BlockScope(scope); | 4218 Scope blockScope = new BlockScope(scope); |
| 4217 visitForInDeclaredIdentifierIn(node.declaredIdentifier, node, blockScope); | 4219 visitForInDeclaredIdentifierIn(node.declaredIdentifier, node, blockScope); |
| 4218 visitLoopBodyIn(node, node.body, blockScope); | 4220 visitLoopBodyIn(node, node.body, blockScope); |
| 4219 return const NoneResult(); | 4221 return const NoneResult(); |
| 4220 } | 4222 } |
| 4221 | 4223 |
| 4222 void visitForInDeclaredIdentifierIn( | 4224 void visitForInDeclaredIdentifierIn( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4234 VariableDefinitions variableDefinitions = | 4236 VariableDefinitions variableDefinitions = |
| 4235 declaration.asVariableDefinitions(); | 4237 declaration.asVariableDefinitions(); |
| 4236 Element loopVariable; | 4238 Element loopVariable; |
| 4237 Selector loopVariableSelector; | 4239 Selector loopVariableSelector; |
| 4238 if (send != null) { | 4240 if (send != null) { |
| 4239 loopVariable = registry.getDefinition(send); | 4241 loopVariable = registry.getDefinition(send); |
| 4240 Identifier identifier = send.selector.asIdentifier(); | 4242 Identifier identifier = send.selector.asIdentifier(); |
| 4241 if (identifier == null) { | 4243 if (identifier == null) { |
| 4242 compiler.reportError(send.selector, MessageKind.INVALID_FOR_IN); | 4244 compiler.reportError(send.selector, MessageKind.INVALID_FOR_IN); |
| 4243 } else { | 4245 } else { |
| 4244 loopVariableSelector = new Selector.setter(identifier.source, library); | 4246 loopVariableSelector = new Selector.setter( |
| 4247 new Name(identifier.source, library)); |
| 4245 } | 4248 } |
| 4246 if (send.receiver != null) { | 4249 if (send.receiver != null) { |
| 4247 compiler.reportError(send.receiver, MessageKind.INVALID_FOR_IN); | 4250 compiler.reportError(send.receiver, MessageKind.INVALID_FOR_IN); |
| 4248 } | 4251 } |
| 4249 } else if (variableDefinitions != null) { | 4252 } else if (variableDefinitions != null) { |
| 4250 Link<Node> nodes = variableDefinitions.definitions.nodes; | 4253 Link<Node> nodes = variableDefinitions.definitions.nodes; |
| 4251 if (!nodes.tail.isEmpty) { | 4254 if (!nodes.tail.isEmpty) { |
| 4252 compiler.reportError(nodes.tail.head, MessageKind.INVALID_FOR_IN); | 4255 compiler.reportError(nodes.tail.head, MessageKind.INVALID_FOR_IN); |
| 4253 } | 4256 } |
| 4254 Node first = nodes.head; | 4257 Node first = nodes.head; |
| 4255 Identifier identifier = first.asIdentifier(); | 4258 Identifier identifier = first.asIdentifier(); |
| 4256 if (identifier == null) { | 4259 if (identifier == null) { |
| 4257 compiler.reportError(first, MessageKind.INVALID_FOR_IN); | 4260 compiler.reportError(first, MessageKind.INVALID_FOR_IN); |
| 4258 } else { | 4261 } else { |
| 4259 loopVariableSelector = new Selector.setter(identifier.source, library); | 4262 loopVariableSelector = new Selector.setter( |
| 4263 new Name(identifier.source, library)); |
| 4260 loopVariable = registry.getDefinition(identifier); | 4264 loopVariable = registry.getDefinition(identifier); |
| 4261 } | 4265 } |
| 4262 } else { | 4266 } else { |
| 4263 compiler.reportError(declaration, MessageKind.INVALID_FOR_IN); | 4267 compiler.reportError(declaration, MessageKind.INVALID_FOR_IN); |
| 4264 } | 4268 } |
| 4265 if (loopVariableSelector != null) { | 4269 if (loopVariableSelector != null) { |
| 4266 registry.setSelector(declaration, loopVariableSelector); | 4270 registry.setSelector(declaration, loopVariableSelector); |
| 4267 registerSend(loopVariableSelector, loopVariable); | 4271 registerSend(loopVariableSelector, loopVariable); |
| 4268 } else { | 4272 } else { |
| 4269 // The selector may only be null if we reported an error. | 4273 // The selector may only be null if we reported an error. |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4637 } | 4641 } |
| 4638 return const NoneResult(); | 4642 return const NoneResult(); |
| 4639 } | 4643 } |
| 4640 } | 4644 } |
| 4641 | 4645 |
| 4642 /// Looks up [name] in [scope] and unwraps the result. | 4646 /// Looks up [name] in [scope] and unwraps the result. |
| 4643 Element lookupInScope(Compiler compiler, Node node, | 4647 Element lookupInScope(Compiler compiler, Node node, |
| 4644 Scope scope, String name) { | 4648 Scope scope, String name) { |
| 4645 return Elements.unwrap(scope.lookup(name), compiler, node); | 4649 return Elements.unwrap(scope.lookup(name), compiler, node); |
| 4646 } | 4650 } |
| OLD | NEW |