| 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 }); | 521 }); |
| 522 } | 522 } |
| 523 | 523 |
| 524 /// This method should only be used by this library (or tests of | 524 /// This method should only be used by this library (or tests of |
| 525 /// this library). | 525 /// this library). |
| 526 ResolverVisitor visitorFor(Element element) { | 526 ResolverVisitor visitorFor(Element element) { |
| 527 var mapping = new TreeElementMapping(element); | 527 var mapping = new TreeElementMapping(element); |
| 528 return new ResolverVisitor(compiler, element, mapping); | 528 return new ResolverVisitor(compiler, element, mapping); |
| 529 } | 529 } |
| 530 | 530 |
| 531 void visitBody(ResolverVisitor visitor, Statement body) { | |
| 532 if (!compiler.analyzeSignaturesOnly) { | |
| 533 visitor.visit(body); | |
| 534 } | |
| 535 } | |
| 536 | |
| 537 TreeElements resolveField(VariableElement element) { | 531 TreeElements resolveField(VariableElement element) { |
| 538 Node tree = element.parseNode(compiler); | 532 Node tree = element.parseNode(compiler); |
| 539 if(element.modifiers.isStatic() && element.variables.isTopLevel()) { | 533 if(element.modifiers.isStatic() && element.variables.isTopLevel()) { |
| 540 error(element.modifiers.getStatic(), | 534 error(element.modifiers.getStatic(), |
| 541 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC); | 535 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC); |
| 542 } | 536 } |
| 543 ResolverVisitor visitor = visitorFor(element); | 537 ResolverVisitor visitor = visitorFor(element); |
| 544 visitor.useElement(tree, element); | 538 visitor.useElement(tree, element); |
| 545 | 539 |
| 546 SendSet send = tree.asSendSet(); | 540 SendSet send = tree.asSendSet(); |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 : MessageKind.NO_MATCHING_CONSTRUCTOR; | 1411 : MessageKind.NO_MATCHING_CONSTRUCTOR; |
| 1418 visitor.compiler.reportError(diagnosticNode, kind); | 1412 visitor.compiler.reportError(diagnosticNode, kind); |
| 1419 } else if (caller.modifiers.isConst() | 1413 } else if (caller.modifiers.isConst() |
| 1420 && !lookedupConstructor.modifiers.isConst()) { | 1414 && !lookedupConstructor.modifiers.isConst()) { |
| 1421 visitor.compiler.reportError( | 1415 visitor.compiler.reportError( |
| 1422 diagnosticNode, MessageKind.CONST_CALLS_NON_CONST); | 1416 diagnosticNode, MessageKind.CONST_CALLS_NON_CONST); |
| 1423 } | 1417 } |
| 1424 } | 1418 } |
| 1425 } | 1419 } |
| 1426 | 1420 |
| 1427 FunctionElement resolveRedirection(FunctionElement constructor, | |
| 1428 FunctionExpression functionNode) { | |
| 1429 if (functionNode.initializers == null) return null; | |
| 1430 Link<Node> link = functionNode.initializers.nodes; | |
| 1431 if (!link.isEmpty && Initializers.isConstructorRedirect(link.head)) { | |
| 1432 return resolveSuperOrThisForSend(constructor, functionNode, link.head); | |
| 1433 } | |
| 1434 return null; | |
| 1435 } | |
| 1436 | |
| 1437 /** | 1421 /** |
| 1438 * Resolve all initializers of this constructor. In the case of a redirecting | 1422 * Resolve all initializers of this constructor. In the case of a redirecting |
| 1439 * constructor, the resolved constructor's function element is returned. | 1423 * constructor, the resolved constructor's function element is returned. |
| 1440 */ | 1424 */ |
| 1441 FunctionElement resolveInitializers(FunctionElement constructor, | 1425 FunctionElement resolveInitializers(FunctionElement constructor, |
| 1442 FunctionExpression functionNode) { | 1426 FunctionExpression functionNode) { |
| 1443 // Keep track of all "this.param" parameters specified for constructor so | 1427 // Keep track of all "this.param" parameters specified for constructor so |
| 1444 // that we can ensure that fields are initialized only once. | 1428 // that we can ensure that fields are initialized only once. |
| 1445 FunctionSignature functionParameters = | 1429 FunctionSignature functionParameters = |
| 1446 constructor.computeSignature(visitor.compiler); | 1430 constructor.computeSignature(visitor.compiler); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 | 1505 |
| 1522 R visitEmptyStatement(Node node) => null; | 1506 R visitEmptyStatement(Node node) => null; |
| 1523 | 1507 |
| 1524 /** Convenience method for visiting nodes that may be null. */ | 1508 /** Convenience method for visiting nodes that may be null. */ |
| 1525 R visit(Node node) => (node == null) ? null : node.accept(this); | 1509 R visit(Node node) => (node == null) ? null : node.accept(this); |
| 1526 | 1510 |
| 1527 void error(Node node, MessageKind kind, [Map arguments = const {}]) { | 1511 void error(Node node, MessageKind kind, [Map arguments = const {}]) { |
| 1528 compiler.reportFatalError(node, kind, arguments); | 1512 compiler.reportFatalError(node, kind, arguments); |
| 1529 } | 1513 } |
| 1530 | 1514 |
| 1531 void dualError(Node node, DualKind kind, [Map arguments = const {}]) { | |
| 1532 error(node, kind.error, arguments); | |
| 1533 } | |
| 1534 | |
| 1535 void warning(Node node, MessageKind kind, [Map arguments = const {}]) { | 1515 void warning(Node node, MessageKind kind, [Map arguments = const {}]) { |
| 1536 ResolutionWarning message = | 1516 ResolutionWarning message = |
| 1537 new ResolutionWarning(kind, arguments, compiler.terseDiagnostics); | 1517 new ResolutionWarning(kind, arguments, compiler.terseDiagnostics); |
| 1538 compiler.reportWarning(node, message); | 1518 compiler.reportWarning(node, message); |
| 1539 } | 1519 } |
| 1540 | 1520 |
| 1541 void dualWarning(Node node, DualKind kind, [Map arguments = const {}]) { | |
| 1542 warning(node, kind.warning, arguments); | |
| 1543 } | |
| 1544 | |
| 1545 void cancel(Node node, String message) { | 1521 void cancel(Node node, String message) { |
| 1546 compiler.cancel(message, node: node); | 1522 compiler.cancel(message, node: node); |
| 1547 } | 1523 } |
| 1548 | 1524 |
| 1549 void internalError(Node node, String message) { | 1525 void internalError(Node node, String message) { |
| 1550 compiler.internalError(message, node: node); | 1526 compiler.internalError(message, node: node); |
| 1551 } | 1527 } |
| 1552 | 1528 |
| 1553 void unimplemented(Node node, String message) { | 1529 void unimplemented(Node node, String message) { |
| 1554 compiler.unimplemented(message, node: node); | 1530 compiler.unimplemented(message, node: node); |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2327 world.registerInstantiatedClass(compiler.functionClass, mapping); | 2303 world.registerInstantiatedClass(compiler.functionClass, mapping); |
| 2328 } | 2304 } |
| 2329 | 2305 |
| 2330 visitIf(If node) { | 2306 visitIf(If node) { |
| 2331 doInPromotionScope(node.condition.expression, () => visit(node.condition)); | 2307 doInPromotionScope(node.condition.expression, () => visit(node.condition)); |
| 2332 doInPromotionScope(node.thenPart, | 2308 doInPromotionScope(node.thenPart, |
| 2333 () => visitIn(node.thenPart, new BlockScope(scope))); | 2309 () => visitIn(node.thenPart, new BlockScope(scope))); |
| 2334 visitIn(node.elsePart, new BlockScope(scope)); | 2310 visitIn(node.elsePart, new BlockScope(scope)); |
| 2335 } | 2311 } |
| 2336 | 2312 |
| 2337 static bool isLogicalOperator(Identifier op) { | |
| 2338 String str = op.source; | |
| 2339 return (identical(str, '&&') || str == '||' || str == '!'); | |
| 2340 } | |
| 2341 | |
| 2342 Element resolveSend(Send node) { | 2313 Element resolveSend(Send node) { |
| 2343 Selector selector = resolveSelector(node, null); | 2314 Selector selector = resolveSelector(node, null); |
| 2344 if (node.isSuperCall) mapping.superUses.add(node); | 2315 if (node.isSuperCall) mapping.superUses.add(node); |
| 2345 | 2316 |
| 2346 if (node.receiver == null) { | 2317 if (node.receiver == null) { |
| 2347 // If this send is of the form "assert(expr);", then | 2318 // If this send is of the form "assert(expr);", then |
| 2348 // this is an assertion. | 2319 // this is an assertion. |
| 2349 if (selector.isAssert()) { | 2320 if (selector.isAssert()) { |
| 2350 if (selector.argumentCount != 1) { | 2321 if (selector.argumentCount != 1) { |
| 2351 error(node.selector, | 2322 error(node.selector, |
| (...skipping 2396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4748 return finishConstructorReference(visit(expression), | 4719 return finishConstructorReference(visit(expression), |
| 4749 expression, expression); | 4720 expression, expression); |
| 4750 } | 4721 } |
| 4751 } | 4722 } |
| 4752 | 4723 |
| 4753 /// Looks up [name] in [scope] and unwraps the result. | 4724 /// Looks up [name] in [scope] and unwraps the result. |
| 4754 Element lookupInScope(Compiler compiler, Node node, | 4725 Element lookupInScope(Compiler compiler, Node node, |
| 4755 Scope scope, String name) { | 4726 Scope scope, String name) { |
| 4756 return Elements.unwrap(scope.lookup(name), compiler, node); | 4727 return Elements.unwrap(scope.lookup(name), compiler, node); |
| 4757 } | 4728 } |
| OLD | NEW |