| 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 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 push(type); | 1675 push(type); |
| 1676 push(typeArguments ?? NullValue.TypeArguments); | 1676 push(typeArguments ?? NullValue.TypeArguments); |
| 1677 push(name); | 1677 push(name); |
| 1678 } | 1678 } |
| 1679 | 1679 |
| 1680 @override | 1680 @override |
| 1681 Expression buildStaticInvocation(Member target, Arguments arguments, | 1681 Expression buildStaticInvocation(Member target, Arguments arguments, |
| 1682 {bool isConst: false, int charOffset: -1}) { | 1682 {bool isConst: false, int charOffset: -1}) { |
| 1683 List<TypeParameter> typeParameters = target.function.typeParameters; | 1683 List<TypeParameter> typeParameters = target.function.typeParameters; |
| 1684 if (target is Constructor) { | 1684 if (target is Constructor) { |
| 1685 assert(!target.enclosingClass.isAbstract); |
| 1685 typeParameters = target.enclosingClass.typeParameters; | 1686 typeParameters = target.enclosingClass.typeParameters; |
| 1686 } | 1687 } |
| 1687 if (!checkArguments(target.function, arguments, typeParameters)) { | 1688 if (!checkArguments(target.function, arguments, typeParameters)) { |
| 1688 return throwNoSuchMethodError(target.name.name, arguments, charOffset); | 1689 return throwNoSuchMethodError(target.name.name, arguments, charOffset); |
| 1689 } | 1690 } |
| 1690 if (target is Constructor) { | 1691 if (target is Constructor) { |
| 1691 return new ConstructorInvocation(target, arguments) | 1692 return new ConstructorInvocation(target, arguments) |
| 1692 ..isConst = isConst | 1693 ..isConst = isConst |
| 1693 ..fileOffset = charOffset; | 1694 ..fileOffset = charOffset; |
| 1694 } else { | 1695 } else { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 } | 1769 } |
| 1769 | 1770 |
| 1770 String errorName; | 1771 String errorName; |
| 1771 if (type is ClassBuilder) { | 1772 if (type is ClassBuilder) { |
| 1772 Builder b = type.findConstructorOrFactory(name); | 1773 Builder b = type.findConstructorOrFactory(name); |
| 1773 Member target; | 1774 Member target; |
| 1774 if (b == null) { | 1775 if (b == null) { |
| 1775 // Not found. Reported below. | 1776 // Not found. Reported below. |
| 1776 } else if (b.isConstructor) { | 1777 } else if (b.isConstructor) { |
| 1777 if (type.isAbstract) { | 1778 if (type.isAbstract) { |
| 1778 // TODO(ahe): Generate abstract instantiation error. | 1779 push(buildMethodInvocation( |
| 1780 buildAbstractClassInstantiationError( |
| 1781 type.name, nameToken.charOffset), |
| 1782 callName, |
| 1783 arguments, |
| 1784 arguments.fileOffset)); |
| 1785 return; |
| 1779 } else { | 1786 } else { |
| 1780 target = b.target; | 1787 target = b.target; |
| 1781 } | 1788 } |
| 1782 } else if (b.isFactory) { | 1789 } else if (b.isFactory) { |
| 1783 target = getRedirectionTarget(b.target); | 1790 target = getRedirectionTarget(b.target); |
| 1784 if (target == null) { | 1791 if (target == null) { |
| 1785 push(buildCompileTimeError( | 1792 push(buildCompileTimeError( |
| 1786 "Cyclic definition of factory '${name}'.", | 1793 "Cyclic definition of factory '${name}'.", |
| 1787 nameToken.charOffset)); | 1794 nameToken.charOffset)); |
| 1788 return; | 1795 return; |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2345 } | 2352 } |
| 2346 return super.handleUnrecoverableError(token, kind, arguments); | 2353 return super.handleUnrecoverableError(token, kind, arguments); |
| 2347 } | 2354 } |
| 2348 | 2355 |
| 2349 @override | 2356 @override |
| 2350 Expression buildCompileTimeError(error, [int charOffset = -1]) { | 2357 Expression buildCompileTimeError(error, [int charOffset = -1]) { |
| 2351 addCompileTimeError(charOffset, error); | 2358 addCompileTimeError(charOffset, error); |
| 2352 String message = formatUnexpected(uri, charOffset, error); | 2359 String message = formatUnexpected(uri, charOffset, error); |
| 2353 Builder constructor = library.loader.getCompileTimeError(); | 2360 Builder constructor = library.loader.getCompileTimeError(); |
| 2354 return new Throw(buildStaticInvocation(constructor.target, | 2361 return new Throw(buildStaticInvocation(constructor.target, |
| 2355 new Arguments(<Expression>[new StringLiteral(message)]), | 2362 new Arguments(<Expression>[new StringLiteral(message)]))); |
| 2356 isConst: false)); // TODO(ahe): Make this const. | 2363 } |
| 2364 |
| 2365 Expression buildAbstractClassInstantiationError(String className, |
| 2366 [int charOffset = -1]) { |
| 2367 warning("The class '$className' is abstract and can't be instantiated.", |
| 2368 charOffset); |
| 2369 Builder constructor = library.loader.getAbstractClassInstantiationError(); |
| 2370 return new Throw(buildStaticInvocation(constructor.target, |
| 2371 new Arguments(<Expression>[new StringLiteral(className)]))); |
| 2357 } | 2372 } |
| 2358 | 2373 |
| 2359 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) { | 2374 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) { |
| 2360 return new ExpressionStatement(buildCompileTimeError(error, charOffset)); | 2375 return new ExpressionStatement(buildCompileTimeError(error, charOffset)); |
| 2361 } | 2376 } |
| 2362 | 2377 |
| 2363 @override | 2378 @override |
| 2364 Initializer buildCompileTimeErrorIntializer(error, [int charOffset = -1]) { | 2379 Initializer buildCompileTimeErrorIntializer(error, [int charOffset = -1]) { |
| 2365 return new LocalInitializer(new VariableDeclaration.forValue( | 2380 return new LocalInitializer(new VariableDeclaration.forValue( |
| 2366 buildCompileTimeError(error, charOffset))); | 2381 buildCompileTimeError(error, charOffset))); |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 } else if (node is PrefixBuilder) { | 2895 } else if (node is PrefixBuilder) { |
| 2881 return node.name; | 2896 return node.name; |
| 2882 } else if (node is ThisAccessor) { | 2897 } else if (node is ThisAccessor) { |
| 2883 return node.isSuper ? "super" : "this"; | 2898 return node.isSuper ? "super" : "this"; |
| 2884 } else if (node is FastaAccessor) { | 2899 } else if (node is FastaAccessor) { |
| 2885 return node.plainNameForRead; | 2900 return node.plainNameForRead; |
| 2886 } else { | 2901 } else { |
| 2887 return internalError("Unhandled: ${node.runtimeType}"); | 2902 return internalError("Unhandled: ${node.runtimeType}"); |
| 2888 } | 2903 } |
| 2889 } | 2904 } |
| OLD | NEW |