Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.body_builder; | 5 library fasta.body_builder; |
| 6 | 6 |
| 7 import '../parser/parser.dart' show FormalParameterType, optional; | 7 import '../parser/parser.dart' show FormalParameterType, optional; |
| 8 | 8 |
| 9 import '../parser/error_kind.dart' show ErrorKind; | 9 import '../parser/error_kind.dart' show ErrorKind; |
| 10 | 10 |
| (...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1738 } | 1738 } |
| 1739 | 1739 |
| 1740 @override | 1740 @override |
| 1741 void endNewExpression(Token token) { | 1741 void endNewExpression(Token token) { |
| 1742 debugEvent("NewExpression"); | 1742 debugEvent("NewExpression"); |
| 1743 Token nameToken = token.next; | 1743 Token nameToken = token.next; |
| 1744 Arguments arguments = pop(); | 1744 Arguments arguments = pop(); |
| 1745 String name = pop(); | 1745 String name = pop(); |
| 1746 List<DartType> typeArguments = pop(); | 1746 List<DartType> typeArguments = pop(); |
| 1747 var type = pop(); | 1747 var type = pop(); |
| 1748 constantExpressionRequired = pop(); | 1748 bool savedConstantExpressionRequired = pop(); |
| 1749 try { | |
| 1750 if (arguments == null) { | |
|
karlklose
2017/03/24 08:54:08
Could you move this code into a local function ins
ahe
2017/03/24 12:47:58
Done.
| |
| 1751 push(buildCompileTimeError("No arguments.", nameToken.charOffset)); | |
| 1752 return; | |
| 1753 } | |
| 1749 | 1754 |
| 1750 if (arguments == null) { | 1755 if (typeArguments != null) { |
| 1751 push(buildCompileTimeError("No arguments.", nameToken.charOffset)); | 1756 assert(arguments.types.isEmpty); |
| 1752 return; | 1757 arguments.types.addAll(typeArguments); |
| 1758 } | |
| 1759 | |
| 1760 String errorName; | |
| 1761 if (type is ClassBuilder) { | |
| 1762 Builder b = type.findConstructorOrFactory(name); | |
| 1763 Member target; | |
| 1764 if (b == null) { | |
| 1765 // Not found. Reported below. | |
| 1766 } else if (b.isConstructor) { | |
| 1767 if (type.isAbstract) { | |
| 1768 // TODO(ahe): Generate abstract instantiation error. | |
| 1769 } else { | |
| 1770 target = b.target; | |
| 1771 } | |
| 1772 } else if (b.isFactory) { | |
| 1773 target = getRedirectionTarget(b.target); | |
| 1774 if (target == null) { | |
| 1775 push(buildCompileTimeError( | |
| 1776 "Cyclic definition of factory '${name}'.", | |
| 1777 nameToken.charOffset)); | |
| 1778 return; | |
| 1779 } | |
| 1780 } | |
| 1781 if (target is Constructor || | |
| 1782 (target is Procedure && target.kind == ProcedureKind.Factory)) { | |
| 1783 push(buildStaticInvocation(target, arguments, | |
| 1784 isConst: optional("const", token), | |
| 1785 charOffset: nameToken.charOffset)); | |
| 1786 return; | |
| 1787 } else { | |
| 1788 errorName = debugName(type.name, name); | |
| 1789 } | |
| 1790 } else { | |
| 1791 errorName = debugName(getNodeName(type), name); | |
| 1792 } | |
| 1793 errorName ??= name; | |
| 1794 push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset)); | |
| 1795 } finally { | |
| 1796 constantExpressionRequired = savedConstantExpressionRequired; | |
| 1753 } | 1797 } |
| 1754 | |
| 1755 if (typeArguments != null) { | |
| 1756 assert(arguments.types.isEmpty); | |
| 1757 arguments.types.addAll(typeArguments); | |
| 1758 } | |
| 1759 | |
| 1760 String errorName; | |
| 1761 if (type is ClassBuilder) { | |
| 1762 Builder b = type.findConstructorOrFactory(name); | |
| 1763 Member target; | |
| 1764 if (b == null) { | |
| 1765 // Not found. Reported below. | |
| 1766 } else if (b.isConstructor) { | |
| 1767 if (type.isAbstract) { | |
| 1768 // TODO(ahe): Generate abstract instantiation error. | |
| 1769 } else { | |
| 1770 target = b.target; | |
| 1771 } | |
| 1772 } else if (b.isFactory) { | |
| 1773 target = getRedirectionTarget(b.target); | |
| 1774 if (target == null) { | |
| 1775 push(buildCompileTimeError( | |
| 1776 "Cyclic definition of factory '${name}'.", nameToken.charOffset)); | |
| 1777 return; | |
| 1778 } | |
| 1779 } | |
| 1780 if (target is Constructor || | |
| 1781 (target is Procedure && target.kind == ProcedureKind.Factory)) { | |
| 1782 push(buildStaticInvocation(target, arguments, | |
| 1783 isConst: optional("const", token), | |
| 1784 charOffset: nameToken.charOffset)); | |
| 1785 return; | |
| 1786 } else { | |
| 1787 errorName = debugName(type.name, name); | |
| 1788 } | |
| 1789 } else { | |
| 1790 errorName = debugName(getNodeName(type), name); | |
| 1791 } | |
| 1792 errorName ??= name; | |
| 1793 push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset)); | |
| 1794 } | 1798 } |
| 1795 | 1799 |
| 1796 @override | 1800 @override |
| 1797 void endConstExpression(Token token) { | 1801 void endConstExpression(Token token) { |
| 1798 debugEvent("endConstExpression"); | 1802 debugEvent("endConstExpression"); |
| 1799 endNewExpression(token); | 1803 endNewExpression(token); |
| 1800 } | 1804 } |
| 1801 | 1805 |
| 1802 @override | 1806 @override |
| 1803 void endTypeArguments(int count, Token beginToken, Token endToken) { | 1807 void endTypeArguments(int count, Token beginToken, Token endToken) { |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2846 } else if (node is PrefixBuilder) { | 2850 } else if (node is PrefixBuilder) { |
| 2847 return node.name; | 2851 return node.name; |
| 2848 } else if (node is ThisAccessor) { | 2852 } else if (node is ThisAccessor) { |
| 2849 return node.isSuper ? "super" : "this"; | 2853 return node.isSuper ? "super" : "this"; |
| 2850 } else if (node is BuilderAccessor) { | 2854 } else if (node is BuilderAccessor) { |
| 2851 return node.plainNameForRead; | 2855 return node.plainNameForRead; |
| 2852 } else { | 2856 } else { |
| 2853 return internalError("Unhandled: ${node.runtimeType}"); | 2857 return internalError("Unhandled: ${node.runtimeType}"); |
| 2854 } | 2858 } |
| 2855 } | 2859 } |
| OLD | NEW |