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 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1546 Element get enclosingElement; | 1546 Element get enclosingElement; |
| 1547 /// The current scope of the visitor. | 1547 /// The current scope of the visitor. |
| 1548 Scope get scope; | 1548 Scope get scope; |
| 1549 | 1549 |
| 1550 MappingVisitor(Compiler compiler, TreeElementMapping this.mapping) | 1550 MappingVisitor(Compiler compiler, TreeElementMapping this.mapping) |
| 1551 : typeResolver = new TypeResolver(compiler), | 1551 : typeResolver = new TypeResolver(compiler), |
| 1552 super(compiler); | 1552 super(compiler); |
| 1553 | 1553 |
| 1554 Element useElement(Node node, Element element) { | 1554 Element useElement(Node node, Element element) { |
| 1555 if (element == null) return null; | 1555 if (element == null) return null; |
| 1556 return mapping[node] = element; | 1556 return mapping[node] = element.declaration; |
|
Johnni Winther
2013/05/08 08:22:08
I'm not sure this works with the current invariant
ahe
2013/05/08 08:57:43
Good you spotted this, then. The problem is that
| |
| 1557 } | 1557 } |
| 1558 | 1558 |
| 1559 DartType useType(TypeAnnotation annotation, DartType type) { | 1559 DartType useType(TypeAnnotation annotation, DartType type) { |
| 1560 if (type != null) { | 1560 if (type != null) { |
| 1561 mapping.setType(annotation, type); | 1561 mapping.setType(annotation, type); |
| 1562 useElement(annotation, type.element); | 1562 useElement(annotation, type.element); |
| 1563 } | 1563 } |
| 1564 return type; | 1564 return type; |
| 1565 } | 1565 } |
| 1566 } | 1566 } |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2492 bool oldSendIsMemberAccess = sendIsMemberAccess; | 2492 bool oldSendIsMemberAccess = sendIsMemberAccess; |
| 2493 sendIsMemberAccess = false; | 2493 sendIsMemberAccess = false; |
| 2494 visit(node.expression); | 2494 visit(node.expression); |
| 2495 sendIsMemberAccess = oldSendIsMemberAccess; | 2495 sendIsMemberAccess = oldSendIsMemberAccess; |
| 2496 } | 2496 } |
| 2497 | 2497 |
| 2498 visitNewExpression(NewExpression node) { | 2498 visitNewExpression(NewExpression node) { |
| 2499 Node selector = node.send.selector; | 2499 Node selector = node.send.selector; |
| 2500 FunctionElement constructor = resolveConstructor(node); | 2500 FunctionElement constructor = resolveConstructor(node); |
| 2501 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; | 2501 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; |
| 2502 if (!node.isConst() && isSymbolConstructor) { | |
| 2503 compiler.reportWarningCode( | |
| 2504 node.newToken, MessageKind.NON_CONST_BLOAT, | |
| 2505 {'name': compiler.symbolClass.name}); | |
| 2506 } | |
| 2507 resolveSelector(node.send, constructor); | 2502 resolveSelector(node.send, constructor); |
| 2508 resolveArguments(node.send.argumentsNode); | 2503 resolveArguments(node.send.argumentsNode); |
| 2509 useElement(node.send, constructor); | 2504 useElement(node.send, constructor); |
| 2510 if (Elements.isUnresolved(constructor)) return constructor; | 2505 if (Elements.isUnresolved(constructor)) return constructor; |
| 2511 Selector callSelector = mapping.getSelector(node.send); | 2506 Selector callSelector = mapping.getSelector(node.send); |
| 2512 if (!callSelector.applies(constructor, compiler)) { | 2507 if (!callSelector.applies(constructor, compiler)) { |
| 2513 warnArgumentMismatch(node.send, constructor); | 2508 warnArgumentMismatch(node.send, constructor); |
| 2514 compiler.backend.registerThrowNoSuchMethod(mapping); | 2509 compiler.backend.registerThrowNoSuchMethod(mapping); |
| 2515 } | 2510 } |
| 2516 | 2511 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2528 } | 2523 } |
| 2529 // [cls] might be the declaration element and we want to include injected | 2524 // [cls] might be the declaration element and we want to include injected |
| 2530 // members. | 2525 // members. |
| 2531 cls.implementation.forEachInstanceField( | 2526 cls.implementation.forEachInstanceField( |
| 2532 (ClassElement enclosingClass, Element member) { | 2527 (ClassElement enclosingClass, Element member) { |
| 2533 world.addToWorkList(member); | 2528 world.addToWorkList(member); |
| 2534 }, | 2529 }, |
| 2535 includeBackendMembers: false, | 2530 includeBackendMembers: false, |
| 2536 includeSuperMembers: true); | 2531 includeSuperMembers: true); |
| 2537 | 2532 |
| 2538 if (node.isConst() && isSymbolConstructor) { | 2533 if (isSymbolConstructor) { |
| 2539 Node argumentNode = node.send.arguments.head; | 2534 if (node.isConst()) { |
| 2540 Constant name = compiler.metadataHandler.compileNodeWithDefinitions( | 2535 Node argumentNode = node.send.arguments.head; |
| 2541 argumentNode, mapping, isConst: true); | 2536 Constant name = compiler.metadataHandler.compileNodeWithDefinitions( |
| 2542 if (!name.isString()) { | 2537 argumentNode, mapping, isConst: true); |
| 2543 DartType type = name.computeType(compiler); | 2538 if (!name.isString()) { |
| 2544 compiler.reportErrorCode(argumentNode, MessageKind.STRING_EXPECTED, | 2539 DartType type = name.computeType(compiler); |
| 2545 {'type': type}); | 2540 compiler.reportErrorCode(argumentNode, MessageKind.STRING_EXPECTED, |
| 2541 {'type': type}); | |
| 2542 } else { | |
| 2543 StringConstant stringConstant = name; | |
| 2544 String nameString = stringConstant.toDartString().slowToString(); | |
| 2545 if (validateSymbol(argumentNode, nameString)) { | |
| 2546 world.registerConstSymbol(nameString, mapping); | |
| 2547 } | |
| 2548 } | |
| 2546 } else { | 2549 } else { |
| 2547 StringConstant stringConstant = name; | 2550 compiler.reportWarningCode( |
| 2548 validateSymbol(argumentNode, | 2551 node.newToken, MessageKind.NON_CONST_BLOAT, |
| 2549 stringConstant.toDartString().slowToString()); | 2552 {'name': compiler.symbolClass.name}); |
| 2553 world.registerNewSymbol(mapping); | |
| 2550 } | 2554 } |
| 2551 } | 2555 } |
| 2552 | 2556 |
| 2553 return null; | 2557 return null; |
| 2554 } | 2558 } |
| 2555 | 2559 |
| 2556 void validateSymbol(Node node, String name) { | 2560 bool validateSymbol(Node node, String name) { |
| 2557 if (name.isEmpty) return; | 2561 if (name.isEmpty) return true; |
| 2558 if (name.startsWith('_')) { | 2562 if (name.startsWith('_')) { |
| 2559 compiler.reportErrorCode(node, MessageKind.PRIVATE_IDENTIFIER, | 2563 compiler.reportErrorCode(node, MessageKind.PRIVATE_IDENTIFIER, |
| 2560 {'value': name}); | 2564 {'value': name}); |
| 2561 return; | 2565 return false; |
| 2562 } | 2566 } |
| 2563 if (!symbolValidationPattern.hasMatch(name)) { | 2567 if (!symbolValidationPattern.hasMatch(name)) { |
| 2564 compiler.reportErrorCode(node, MessageKind.INVALID_SYMBOL, | 2568 compiler.reportErrorCode(node, MessageKind.INVALID_SYMBOL, |
| 2565 {'value': name}); | 2569 {'value': name}); |
| 2570 return false; | |
| 2566 } | 2571 } |
| 2572 return true; | |
| 2567 } | 2573 } |
| 2568 | 2574 |
| 2569 | 2575 |
| 2570 /** | 2576 /** |
| 2571 * Try to resolve the constructor that is referred to by [node]. | 2577 * Try to resolve the constructor that is referred to by [node]. |
| 2572 * Note: this function may return an ErroneousFunctionElement instead of | 2578 * Note: this function may return an ErroneousFunctionElement instead of |
| 2573 * [null], if there is no corresponding constructor, class or library. | 2579 * [null], if there is no corresponding constructor, class or library. |
| 2574 */ | 2580 */ |
| 2575 FunctionElement resolveConstructor(NewExpression node) { | 2581 FunctionElement resolveConstructor(NewExpression node) { |
| 2576 return node.accept(new ConstructorResolver(compiler, this)); | 2582 return node.accept(new ConstructorResolver(compiler, this)); |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3903 return e; | 3909 return e; |
| 3904 } | 3910 } |
| 3905 | 3911 |
| 3906 /// Assumed to be called by [resolveRedirectingFactory]. | 3912 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3907 Element visitReturn(Return node) { | 3913 Element visitReturn(Return node) { |
| 3908 Node expression = node.expression; | 3914 Node expression = node.expression; |
| 3909 return finishConstructorReference(visit(expression), | 3915 return finishConstructorReference(visit(expression), |
| 3910 expression, expression); | 3916 expression, expression); |
| 3911 } | 3917 } |
| 3912 } | 3918 } |
| OLD | NEW |