| 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 library kernel.analyzer.ast_from_analyzer; | 4 library kernel.analyzer.ast_from_analyzer; |
| 5 | 5 |
| 6 import '../ast.dart' as ast; | 6 import '../ast.dart' as ast; |
| 7 import '../frontend/accessors.dart'; | 7 import '../frontend/accessors.dart'; |
| 8 import '../frontend/super_initializers.dart'; | 8 import '../frontend/super_initializers.dart'; |
| 9 import '../log.dart'; | 9 import '../log.dart'; |
| 10 import '../type_algebra.dart'; | 10 import '../type_algebra.dart'; |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 747 } |
| 748 | 748 |
| 749 ast.Expression buildThrowCompileTimeError(String message) { | 749 ast.Expression buildThrowCompileTimeError(String message) { |
| 750 // The spec does not mandate a specific behavior in face of a compile-time | 750 // The spec does not mandate a specific behavior in face of a compile-time |
| 751 // error. We just throw a string. The VM throws an uncatchable exception | 751 // error. We just throw a string. The VM throws an uncatchable exception |
| 752 // for this case. | 752 // for this case. |
| 753 // TOOD(asgerf): Should we add uncatchable exceptions to kernel? | 753 // TOOD(asgerf): Should we add uncatchable exceptions to kernel? |
| 754 return new ast.Throw(new ast.StringLiteral(message)); | 754 return new ast.Throw(new ast.StringLiteral(message)); |
| 755 } | 755 } |
| 756 | 756 |
| 757 ast.Expression buildThrowCompileTimeErrorFromCode(ErrorCode code, |
| 758 [List arguments]) { |
| 759 return buildThrowCompileTimeError(makeErrorMessage(code, arguments)); |
| 760 } |
| 761 |
| 757 static final RegExp _errorMessagePattern = new RegExp(r'\{(\d+)\}'); | 762 static final RegExp _errorMessagePattern = new RegExp(r'\{(\d+)\}'); |
| 758 | 763 |
| 759 /// Throws an exception that will be caught at the function level, to replace | 764 String makeErrorMessage(ErrorCode error, [List arguments]) { |
| 760 /// the entire function with a throw. | |
| 761 emitCompileTimeError(ErrorCode error, [List arguments]) { | |
| 762 String message = error.message; | 765 String message = error.message; |
| 763 if (arguments != null) { | 766 if (arguments != null) { |
| 764 message = message.replaceAllMapped(_errorMessagePattern, (m) { | 767 message = message.replaceAllMapped(_errorMessagePattern, (m) { |
| 765 String numberString = m.group(1); | 768 String numberString = m.group(1); |
| 766 int index = int.parse(numberString); | 769 int index = int.parse(numberString); |
| 767 return arguments[index]; | 770 return arguments[index]; |
| 768 }); | 771 }); |
| 769 } | 772 } |
| 770 throw new _CompilationError(message); | 773 return message; |
| 774 } |
| 775 |
| 776 /// Throws an exception that will be caught at the function level, to replace |
| 777 /// the entire function with a throw. |
| 778 emitCompileTimeError(ErrorCode error, [List arguments]) { |
| 779 throw new _CompilationError(makeErrorMessage(error, arguments)); |
| 771 } | 780 } |
| 772 | 781 |
| 773 ast.Expression buildThrowAbstractClassInstantiationError(String name) { | 782 ast.Expression buildThrowAbstractClassInstantiationError(String name) { |
| 774 return new ast.Throw(new ast.ConstructorInvocation( | 783 return new ast.Throw(new ast.ConstructorInvocation( |
| 775 loader.getCoreClassConstructorReference( | 784 loader.getCoreClassConstructorReference( |
| 776 'AbstractClassInstantiationError'), | 785 'AbstractClassInstantiationError'), |
| 777 new ast.Arguments(<ast.Expression>[new ast.StringLiteral(name)]))); | 786 new ast.Arguments(<ast.Expression>[new ast.StringLiteral(name)]))); |
| 778 } | 787 } |
| 779 | 788 |
| 780 ast.Expression buildThrowFallThroughError() { | 789 ast.Expression buildThrowFallThroughError() { |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 scope.buildThis(), | 1695 scope.buildThis(), |
| 1687 scope.buildName(node), | 1696 scope.buildName(node), |
| 1688 scope.resolveInterfaceGet(element, auxiliary), | 1697 scope.resolveInterfaceGet(element, auxiliary), |
| 1689 scope.resolveInterfaceSet(element, auxiliary)); | 1698 scope.resolveInterfaceSet(element, auxiliary)); |
| 1690 | 1699 |
| 1691 case ElementKind.FUNCTION: | 1700 case ElementKind.FUNCTION: |
| 1692 FunctionElement function = element; | 1701 FunctionElement function = element; |
| 1693 if (isTopLevelFunction(function)) { | 1702 if (isTopLevelFunction(function)) { |
| 1694 return scope.staticAccess(node.name, function); | 1703 return scope.staticAccess(node.name, function); |
| 1695 } | 1704 } |
| 1705 if (function == function.library.loadLibraryFunction) { |
| 1706 return scope.unsupportedFeature('Deferred loading'); |
| 1707 } |
| 1696 return new VariableAccessor(scope.getVariableReference(function)); | 1708 return new VariableAccessor(scope.getVariableReference(function)); |
| 1697 | 1709 |
| 1698 case ElementKind.LOCAL_VARIABLE: | 1710 case ElementKind.LOCAL_VARIABLE: |
| 1699 case ElementKind.PARAMETER: | 1711 case ElementKind.PARAMETER: |
| 1700 VariableElement variable = element; | 1712 VariableElement variable = element; |
| 1701 var type = identical(node.staticType, variable.type) | 1713 var type = identical(node.staticType, variable.type) |
| 1702 ? null | 1714 ? null |
| 1703 : scope.buildType(node.staticType); | 1715 : scope.buildType(node.staticType); |
| 1704 return new VariableAccessor(scope.getVariableReference(element), type); | 1716 return new VariableAccessor(scope.getVariableReference(element), type); |
| 1705 | 1717 |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2730 ast.Constructor constructor = currentMember; | 2742 ast.Constructor constructor = currentMember; |
| 2731 constructor.function = scope.buildFunctionNode(node.parameters, node.body, | 2743 constructor.function = scope.buildFunctionNode(node.parameters, node.body, |
| 2732 inferredReturnType: const ast.VoidType())..parent = constructor; | 2744 inferredReturnType: const ast.VoidType())..parent = constructor; |
| 2733 handleNativeBody(node.body); | 2745 handleNativeBody(node.body); |
| 2734 if (node.body is EmptyFunctionBody && !constructor.isExternal) { | 2746 if (node.body is EmptyFunctionBody && !constructor.isExternal) { |
| 2735 var function = constructor.function; | 2747 var function = constructor.function; |
| 2736 function.body = new ast.EmptyStatement()..parent = function; | 2748 function.body = new ast.EmptyStatement()..parent = function; |
| 2737 } | 2749 } |
| 2738 for (var parameter in node.parameters.parameterElements) { | 2750 for (var parameter in node.parameters.parameterElements) { |
| 2739 if (parameter is FieldFormalParameterElement) { | 2751 if (parameter is FieldFormalParameterElement) { |
| 2740 var initializer = new ast.FieldInitializer( | 2752 ast.Initializer initializer; |
| 2741 scope.getMemberReference(parameter.field), | 2753 if (parameter.field == null) { |
| 2742 new ast.VariableGet(scope.getVariableReference(parameter))); | 2754 initializer = new ast.LocalInitializer( |
| 2755 new ast.VariableDeclaration.forValue(scope |
| 2756 .buildThrowCompileTimeErrorFromCode( |
| 2757 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
| 2758 [parameter.name]))); |
| 2759 } else { |
| 2760 initializer = new ast.FieldInitializer( |
| 2761 scope.getMemberReference(parameter.field), |
| 2762 new ast.VariableGet(scope.getVariableReference(parameter))); |
| 2763 } |
| 2743 constructor.initializers.add(initializer..parent = constructor); | 2764 constructor.initializers.add(initializer..parent = constructor); |
| 2744 } | 2765 } |
| 2745 } | 2766 } |
| 2746 bool hasExplicitConstructorCall = false; | 2767 bool hasExplicitConstructorCall = false; |
| 2747 for (var initializer in node.initializers) { | 2768 for (var initializer in node.initializers) { |
| 2748 var node = scope.buildInitializer(initializer); | 2769 var node = scope.buildInitializer(initializer); |
| 2749 constructor.initializers.add(node..parent = constructor); | 2770 constructor.initializers.add(node..parent = constructor); |
| 2750 if (node is ast.SuperInitializer || node is ast.RedirectingInitializer) { | 2771 if (node is ast.SuperInitializer || node is ast.RedirectingInitializer) { |
| 2751 hasExplicitConstructorCall = true; | 2772 hasExplicitConstructorCall = true; |
| 2752 } | 2773 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2965 if (list[i - 1].compareTo(item) == 0) { | 2986 if (list[i - 1].compareTo(item) == 0) { |
| 2966 ++deleted; | 2987 ++deleted; |
| 2967 } else if (deleted > 0) { | 2988 } else if (deleted > 0) { |
| 2968 list[i - deleted] = item; | 2989 list[i - deleted] = item; |
| 2969 } | 2990 } |
| 2970 } | 2991 } |
| 2971 if (deleted > 0) { | 2992 if (deleted > 0) { |
| 2972 list.length -= deleted; | 2993 list.length -= deleted; |
| 2973 } | 2994 } |
| 2974 } | 2995 } |
| OLD | NEW |