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 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 Set<Node> get superUses; | 9 Set<Node> get superUses; |
| 10 | 10 |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 } | 1072 } |
| 1073 return lookupTarget; | 1073 return lookupTarget; |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 Element resolveSuperOrThisForSend(FunctionElement constructor, | 1076 Element resolveSuperOrThisForSend(FunctionElement constructor, |
| 1077 FunctionExpression functionNode, | 1077 FunctionExpression functionNode, |
| 1078 Send call) { | 1078 Send call) { |
| 1079 // Resolve the selector and the arguments. | 1079 // Resolve the selector and the arguments. |
| 1080 ResolverTask resolver = visitor.compiler.resolver; | 1080 ResolverTask resolver = visitor.compiler.resolver; |
| 1081 visitor.inStaticContext(() { | 1081 visitor.inStaticContext(() { |
| 1082 visitor.resolveSelector(call); | 1082 visitor.resolveSelector(call, null); |
| 1083 visitor.resolveArguments(call.argumentsNode); | 1083 visitor.resolveArguments(call.argumentsNode); |
| 1084 }); | 1084 }); |
| 1085 Selector selector = visitor.mapping.getSelector(call); | 1085 Selector selector = visitor.mapping.getSelector(call); |
| 1086 bool isSuperCall = Initializers.isSuperConstructorCall(call); | 1086 bool isSuperCall = Initializers.isSuperConstructorCall(call); |
| 1087 | 1087 |
| 1088 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor, | 1088 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor, |
| 1089 isSuperCall, | 1089 isSuperCall, |
| 1090 call); | 1090 call); |
| 1091 Selector constructorSelector = | 1091 Selector constructorSelector = |
| 1092 visitor.getRedirectingThisOrSuperConstructorSelector(call); | 1092 visitor.getRedirectingThisOrSuperConstructorSelector(call); |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1990 visit(node.thenPart); | 1990 visit(node.thenPart); |
| 1991 visit(node.elsePart); | 1991 visit(node.elsePart); |
| 1992 } | 1992 } |
| 1993 | 1993 |
| 1994 static bool isLogicalOperator(Identifier op) { | 1994 static bool isLogicalOperator(Identifier op) { |
| 1995 String str = op.source.stringValue; | 1995 String str = op.source.stringValue; |
| 1996 return (identical(str, '&&') || str == '||' || str == '!'); | 1996 return (identical(str, '&&') || str == '||' || str == '!'); |
| 1997 } | 1997 } |
| 1998 | 1998 |
| 1999 Element resolveSend(Send node) { | 1999 Element resolveSend(Send node) { |
| 2000 Selector selector = resolveSelector(node); | 2000 Selector selector = resolveSelector(node, null); |
| 2001 if (node.isSuperCall) mapping.superUses.add(node); | 2001 if (node.isSuperCall) mapping.superUses.add(node); |
| 2002 | 2002 |
| 2003 if (node.receiver == null) { | 2003 if (node.receiver == null) { |
| 2004 // If this send is of the form "assert(expr);", then | 2004 // If this send is of the form "assert(expr);", then |
| 2005 // this is an assertion. | 2005 // this is an assertion. |
| 2006 if (selector.isAssert()) { | 2006 if (selector.isAssert()) { |
| 2007 if (selector.argumentCount != 1) { | 2007 if (selector.argumentCount != 1) { |
| 2008 error(node.selector, | 2008 error(node.selector, |
| 2009 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, | 2009 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, |
| 2010 {'argumentCount': selector.argumentCount}); | 2010 {'argumentCount': selector.argumentCount}); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2113 DartType resolveTypeTest(Node argument) { | 2113 DartType resolveTypeTest(Node argument) { |
| 2114 TypeAnnotation node = argument.asTypeAnnotation(); | 2114 TypeAnnotation node = argument.asTypeAnnotation(); |
| 2115 if (node == null) { | 2115 if (node == null) { |
| 2116 // node is of the form !Type. | 2116 // node is of the form !Type. |
| 2117 node = argument.asSend().receiver.asTypeAnnotation(); | 2117 node = argument.asSend().receiver.asTypeAnnotation(); |
| 2118 if (node == null) compiler.cancel("malformed send"); | 2118 if (node == null) compiler.cancel("malformed send"); |
| 2119 } | 2119 } |
| 2120 return resolveTypeRequired(node); | 2120 return resolveTypeRequired(node); |
| 2121 } | 2121 } |
| 2122 | 2122 |
| 2123 static Selector computeSendSelector(Send node, LibraryElement library) { | 2123 static Selector computeSendSelector(Send node, |
| 2124 LibraryElement library, | |
| 2125 Element element) { | |
| 2124 // First determine if this is part of an assignment. | 2126 // First determine if this is part of an assignment. |
| 2125 bool isSet = node.asSendSet() != null; | 2127 bool isSet = node.asSendSet() != null; |
| 2126 | 2128 |
| 2127 if (node.isIndex) { | 2129 if (node.isIndex) { |
| 2128 return isSet ? new Selector.indexSet() : new Selector.index(); | 2130 return isSet ? new Selector.indexSet() : new Selector.index(); |
| 2129 } | 2131 } |
| 2130 | 2132 |
| 2131 if (node.isOperator) { | 2133 if (node.isOperator) { |
| 2132 SourceString source = node.selector.asOperator().source; | 2134 SourceString source = node.selector.asOperator().source; |
| 2133 String string = source.stringValue; | 2135 String string = source.stringValue; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 2162 !link.isEmpty; | 2164 !link.isEmpty; |
| 2163 link = link.tail) { | 2165 link = link.tail) { |
| 2164 Expression argument = link.head; | 2166 Expression argument = link.head; |
| 2165 NamedArgument namedArgument = argument.asNamedArgument(); | 2167 NamedArgument namedArgument = argument.asNamedArgument(); |
| 2166 if (namedArgument != null) { | 2168 if (namedArgument != null) { |
| 2167 named.add(namedArgument.name.source); | 2169 named.add(namedArgument.name.source); |
| 2168 } | 2170 } |
| 2169 arity++; | 2171 arity++; |
| 2170 } | 2172 } |
| 2171 | 2173 |
| 2174 if (element != null && element.isConstructor()) { | |
|
ahe
2013/04/29 10:07:41
I don't understand what this is for. Is this from
ngeoffray
2013/04/29 10:12:09
No, it's related to that CL. If I don't do that ch
| |
| 2175 return new Selector.callConstructor( | |
| 2176 element.name, library, arity, named); | |
| 2177 } | |
| 2178 | |
| 2172 // If we're invoking a closure, we do not have an identifier. | 2179 // If we're invoking a closure, we do not have an identifier. |
| 2173 return (identifier == null) | 2180 return (identifier == null) |
| 2174 ? new Selector.callClosure(arity, named) | 2181 ? new Selector.callClosure(arity, named) |
| 2175 : new Selector.call(identifier.source, library, arity, named); | 2182 : new Selector.call(identifier.source, library, arity, named); |
| 2176 } | 2183 } |
| 2177 | 2184 |
| 2178 Selector resolveSelector(Send node) { | 2185 Selector resolveSelector(Send node, Element element) { |
| 2179 LibraryElement library = enclosingElement.getLibrary(); | 2186 LibraryElement library = enclosingElement.getLibrary(); |
| 2180 Selector selector = computeSendSelector(node, library); | 2187 Selector selector = computeSendSelector(node, library, element); |
| 2181 if (selector != null) mapping.setSelector(node, selector); | 2188 if (selector != null) mapping.setSelector(node, selector); |
| 2182 return selector; | 2189 return selector; |
| 2183 } | 2190 } |
| 2184 | 2191 |
| 2185 void resolveArguments(NodeList list) { | 2192 void resolveArguments(NodeList list) { |
| 2186 if (list == null) return; | 2193 if (list == null) return; |
| 2187 List<SourceString> seenNamedArguments = <SourceString>[]; | 2194 List<SourceString> seenNamedArguments = <SourceString>[]; |
| 2188 for (Link<Node> link = list.nodes; !link.isEmpty; link = link.tail) { | 2195 for (Link<Node> link = list.nodes; !link.isEmpty; link = link.tail) { |
| 2189 Expression argument = link.head; | 2196 Expression argument = link.head; |
| 2190 visit(argument); | 2197 visit(argument); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2551 | 2558 |
| 2552 visitNewExpression(NewExpression node) { | 2559 visitNewExpression(NewExpression node) { |
| 2553 Node selector = node.send.selector; | 2560 Node selector = node.send.selector; |
| 2554 FunctionElement constructor = resolveConstructor(node); | 2561 FunctionElement constructor = resolveConstructor(node); |
| 2555 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; | 2562 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; |
| 2556 if (!node.isConst() && isSymbolConstructor) { | 2563 if (!node.isConst() && isSymbolConstructor) { |
| 2557 compiler.reportWarningCode( | 2564 compiler.reportWarningCode( |
| 2558 node.newToken, MessageKind.NON_CONST_BLOAT, | 2565 node.newToken, MessageKind.NON_CONST_BLOAT, |
| 2559 {'name': compiler.symbolClass.name}); | 2566 {'name': compiler.symbolClass.name}); |
| 2560 } | 2567 } |
| 2561 resolveSelector(node.send); | 2568 resolveSelector(node.send, constructor); |
| 2562 resolveArguments(node.send.argumentsNode); | 2569 resolveArguments(node.send.argumentsNode); |
| 2563 useElement(node.send, constructor); | 2570 useElement(node.send, constructor); |
| 2564 if (Elements.isUnresolved(constructor)) return constructor; | 2571 if (Elements.isUnresolved(constructor)) return constructor; |
| 2565 Selector callSelector = mapping.getSelector(node.send); | 2572 Selector callSelector = mapping.getSelector(node.send); |
| 2566 if (!callSelector.applies(constructor, compiler)) { | 2573 if (!callSelector.applies(constructor, compiler)) { |
| 2567 warnArgumentMismatch(node.send, constructor); | 2574 warnArgumentMismatch(node.send, constructor); |
| 2568 compiler.backend.registerThrowNoSuchMethod(mapping); | 2575 compiler.backend.registerThrowNoSuchMethod(mapping); |
| 2569 } | 2576 } |
| 2570 compiler.withCurrentElement(constructor, () { | 2577 compiler.withCurrentElement(constructor, () { |
| 2571 FunctionExpression tree = constructor.parseNode(compiler); | 2578 FunctionExpression tree = constructor.parseNode(compiler); |
| (...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3986 return e; | 3993 return e; |
| 3987 } | 3994 } |
| 3988 | 3995 |
| 3989 /// Assumed to be called by [resolveRedirectingFactory]. | 3996 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3990 Element visitReturn(Return node) { | 3997 Element visitReturn(Return node) { |
| 3991 Node expression = node.expression; | 3998 Node expression = node.expression; |
| 3992 return finishConstructorReference(visit(expression), | 3999 return finishConstructorReference(visit(expression), |
| 3993 expression, expression); | 4000 expression, expression); |
| 3994 } | 4001 } |
| 3995 } | 4002 } |
| OLD | NEW |