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 package com.google.dart.compiler.resolver; | 5 package com.google.dart.compiler.resolver; |
| 6 | 6 |
| 7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
| 8 import com.google.common.collect.Lists; | 8 import com.google.common.collect.Lists; |
| 9 import com.google.common.collect.Sets; | 9 import com.google.common.collect.Sets; |
| 10 import com.google.dart.compiler.DartCompilationPhase; | 10 import com.google.dart.compiler.DartCompilationPhase; |
| 11 import com.google.dart.compiler.DartCompilerContext; | 11 import com.google.dart.compiler.DartCompilerContext; |
| 12 import com.google.dart.compiler.ErrorCode; | 12 import com.google.dart.compiler.ErrorCode; |
| 13 import com.google.dart.compiler.ast.DartArrayLiteral; | 13 import com.google.dart.compiler.ast.DartArrayLiteral; |
| 14 import com.google.dart.compiler.ast.DartBinaryExpression; | 14 import com.google.dart.compiler.ast.DartBinaryExpression; |
| 15 import com.google.dart.compiler.ast.DartBlock; | 15 import com.google.dart.compiler.ast.DartBlock; |
| 16 import com.google.dart.compiler.ast.DartBooleanLiteral; | 16 import com.google.dart.compiler.ast.DartBooleanLiteral; |
| 17 import com.google.dart.compiler.ast.DartBreakStatement; | 17 import com.google.dart.compiler.ast.DartBreakStatement; |
| 18 import com.google.dart.compiler.ast.DartCatchBlock; | 18 import com.google.dart.compiler.ast.DartCatchBlock; |
| 19 import com.google.dart.compiler.ast.DartClass; | 19 import com.google.dart.compiler.ast.DartClass; |
| 20 import com.google.dart.compiler.ast.DartClassMember; | |
| 20 import com.google.dart.compiler.ast.DartDoWhileStatement; | 21 import com.google.dart.compiler.ast.DartDoWhileStatement; |
| 21 import com.google.dart.compiler.ast.DartDoubleLiteral; | 22 import com.google.dart.compiler.ast.DartDoubleLiteral; |
| 22 import com.google.dart.compiler.ast.DartExpression; | 23 import com.google.dart.compiler.ast.DartExpression; |
| 23 import com.google.dart.compiler.ast.DartField; | 24 import com.google.dart.compiler.ast.DartField; |
| 24 import com.google.dart.compiler.ast.DartFieldDefinition; | 25 import com.google.dart.compiler.ast.DartFieldDefinition; |
| 25 import com.google.dart.compiler.ast.DartForInStatement; | 26 import com.google.dart.compiler.ast.DartForInStatement; |
| 26 import com.google.dart.compiler.ast.DartForStatement; | 27 import com.google.dart.compiler.ast.DartForStatement; |
| 27 import com.google.dart.compiler.ast.DartFunction; | 28 import com.google.dart.compiler.ast.DartFunction; |
| 28 import com.google.dart.compiler.ast.DartFunctionExpression; | 29 import com.google.dart.compiler.ast.DartFunctionExpression; |
| 29 import com.google.dart.compiler.ast.DartFunctionObjectInvocation; | 30 import com.google.dart.compiler.ast.DartFunctionObjectInvocation; |
| (...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1687 originalTypeArgs.size(), 1); | 1688 originalTypeArgs.size(), 1); |
| 1688 // fall through | 1689 // fall through |
| 1689 case 0: | 1690 case 0: |
| 1690 typeArgs.add(implicitKey); | 1691 typeArgs.add(implicitKey); |
| 1691 DartTypeNode implicitValue = new DartTypeNode(new DartIdentifier("Dyna mic")); | 1692 DartTypeNode implicitValue = new DartTypeNode(new DartIdentifier("Dyna mic")); |
| 1692 typeArgs.add(implicitValue); | 1693 typeArgs.add(implicitValue); |
| 1693 break; | 1694 break; |
| 1694 } | 1695 } |
| 1695 | 1696 |
| 1696 InterfaceType type = | 1697 InterfaceType type = |
| 1697 topLevelContext.instantiateParameterizedType( | 1698 context.instantiateParameterizedType( |
| 1698 defaultLiteralMapType.getElement(), | 1699 defaultLiteralMapType.getElement(), |
| 1699 node, | 1700 node, |
| 1700 typeArgs, | 1701 typeArgs, |
| 1701 inStaticContext(currentMethod), | 1702 inStaticContext(node), |
| 1702 inFactoryContext(currentMethod), | 1703 inFactoryContext(currentMethod), |
| 1703 ResolverErrorCode.NO_SUCH_TYPE); | 1704 ResolverErrorCode.NO_SUCH_TYPE); |
| 1704 // instantiateParametersType() will complain for wrong number of parameter s (!=2) | 1705 // instantiateParametersType() will complain for wrong number of parameter s (!=2) |
| 1706 if (node.isConst()) { | |
| 1707 checkTypeArgumentsInConstLiteral(typeArgs, ResolverErrorCode.CONST_MAP_W ITH_TYPE_VARIABLE); | |
| 1708 } | |
| 1705 recordType(node, type); | 1709 recordType(node, type); |
| 1706 visit(node.getEntries()); | 1710 visit(node.getEntries()); |
| 1707 return null; | 1711 return null; |
| 1708 } | 1712 } |
| 1709 | 1713 |
| 1710 @Override | 1714 @Override |
| 1711 public Element visitArrayLiteral(DartArrayLiteral node) { | 1715 public Element visitArrayLiteral(DartArrayLiteral node) { |
| 1712 List<DartTypeNode> typeArgs = node.getTypeArguments(); | 1716 List<DartTypeNode> typeArgs = node.getTypeArguments(); |
| 1713 InterfaceType type = | 1717 InterfaceType type = |
| 1714 topLevelContext.instantiateParameterizedType( | 1718 context.instantiateParameterizedType( |
| 1715 rawArrayType.getElement(), | 1719 rawArrayType.getElement(), |
| 1716 node, | 1720 node, |
| 1717 typeArgs, | 1721 typeArgs, |
| 1718 inStaticContext(currentMethod), | 1722 inStaticContext(node), |
| 1719 inFactoryContext(currentMethod), | 1723 inFactoryContext(currentMethod), |
| 1720 ResolverErrorCode.NO_SUCH_TYPE); | 1724 ResolverErrorCode.NO_SUCH_TYPE); |
| 1721 // instantiateParametersType() will complain for wrong number of parameter s (!=1) | 1725 // instantiateParametersType() will complain for wrong number of parameter s (!=1) |
| 1726 if (node.isConst()) { | |
| 1727 checkTypeArgumentsInConstLiteral(typeArgs, ResolverErrorCode.CONST_ARRAY _WITH_TYPE_VARIABLE); | |
| 1728 } | |
| 1722 recordType(node, type); | 1729 recordType(node, type); |
| 1723 visit(node.getExpressions()); | 1730 visit(node.getExpressions()); |
| 1724 return null; | 1731 return null; |
| 1725 } | 1732 } |
| 1726 | 1733 |
| 1734 private void checkTypeArgumentsInConstLiteral(List<DartTypeNode> typeArgs, E rrorCode errorCode) { | |
| 1735 for (DartTypeNode typeNode : typeArgs) { | |
| 1736 Type type = typeNode.getType(); | |
| 1737 if (type != null && type.getKind() == TypeKind.VARIABLE) { | |
| 1738 onError(typeNode, errorCode); | |
| 1739 } | |
| 1740 } | |
| 1741 } | |
| 1742 | |
| 1727 private ConstructorElement checkIsConstructor(DartNewExpression source, Elem ent element) { | 1743 private ConstructorElement checkIsConstructor(DartNewExpression source, Elem ent element) { |
| 1728 if (!ElementKind.of(element).equals(ElementKind.CONSTRUCTOR)) { | 1744 if (!ElementKind.of(element).equals(ElementKind.CONSTRUCTOR)) { |
| 1729 onError(source.getConstructor(), ResolverErrorCode.NEW_EXPRESSION_NOT_CO NSTRUCTOR); | 1745 onError(source.getConstructor(), ResolverErrorCode.NEW_EXPRESSION_NOT_CO NSTRUCTOR); |
| 1730 return null; | 1746 return null; |
| 1731 } | 1747 } |
| 1732 return (ConstructorElement) element; | 1748 return (ConstructorElement) element; |
| 1733 } | 1749 } |
| 1734 | 1750 |
| 1735 private void checkConstructor(DartMethodDefinition node, | 1751 private void checkConstructor(DartMethodDefinition node, |
| 1736 ConstructorElement superCall) { | 1752 ConstructorElement superCall) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1812 } | 1828 } |
| 1813 | 1829 |
| 1814 private void onError(HasSourceInfo node, ErrorCode errorCode, Object... argu ments) { | 1830 private void onError(HasSourceInfo node, ErrorCode errorCode, Object... argu ments) { |
| 1815 context.onError(node, errorCode, arguments); | 1831 context.onError(node, errorCode, arguments); |
| 1816 } | 1832 } |
| 1817 | 1833 |
| 1818 private void onError(SourceInfo node, ErrorCode errorCode, Object... argumen ts) { | 1834 private void onError(SourceInfo node, ErrorCode errorCode, Object... argumen ts) { |
| 1819 context.onError(node, errorCode, arguments); | 1835 context.onError(node, errorCode, arguments); |
| 1820 } | 1836 } |
| 1821 | 1837 |
| 1838 private boolean inStaticContext(DartNode node) { | |
| 1839 DartNode anscestor = node; | |
|
zundel
2012/06/07 21:11:19
typo: anscestor -> ancestor
Brian Wilkerson
2012/06/07 21:19:05
Done
| |
| 1840 while (anscestor != null) { | |
| 1841 if (anscestor instanceof DartClassMember<?>) { | |
| 1842 return ((DartClassMember<?>) anscestor).getModifiers().isStatic(); | |
| 1843 } | |
| 1844 anscestor = anscestor.getParent(); | |
| 1845 } | |
| 1846 return true; | |
| 1847 } | |
| 1848 | |
| 1822 private boolean inStaticContext(Element element) { | 1849 private boolean inStaticContext(Element element) { |
| 1823 return element == null || Elements.isTopLevel(element) | 1850 return element == null || Elements.isTopLevel(element) |
| 1824 || element.getModifiers().isStatic() || element.getModifiers().i sFactory(); | 1851 || element.getModifiers().isStatic() || element.getModifiers().i sFactory(); |
| 1825 } | 1852 } |
| 1826 | 1853 |
| 1827 private boolean inFactoryContext(Element element) { | 1854 private boolean inFactoryContext(Element element) { |
| 1828 if (element != null) { | 1855 if (element != null) { |
| 1829 return element.getModifiers().isFactory(); | 1856 return element.getModifiers().isFactory(); |
| 1830 } | 1857 } |
| 1831 return false; | 1858 return false; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1896 ClassElement nextClass = (ClassElement) nextConstructorElement.getEnclos ingElement(); | 1923 ClassElement nextClass = (ClassElement) nextConstructorElement.getEnclos ingElement(); |
| 1897 ClassElement currentClass = (ClassElement) constructor.getEnclosingEleme nt(); | 1924 ClassElement currentClass = (ClassElement) constructor.getEnclosingEleme nt(); |
| 1898 if (nextClass == currentClass) { | 1925 if (nextClass == currentClass) { |
| 1899 return (ConstructorNodeElement) nextConstructorElement; | 1926 return (ConstructorNodeElement) nextConstructorElement; |
| 1900 } | 1927 } |
| 1901 } | 1928 } |
| 1902 } | 1929 } |
| 1903 return null; | 1930 return null; |
| 1904 } | 1931 } |
| 1905 } | 1932 } |
| OLD | NEW |