Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: pkg/kernel/lib/analyzer/ast_from_analyzer.dart

Issue 2638353003: Revert "Fix some crashes in dartk." (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/kernel/lib/analyzer/loader.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
762 static final RegExp _errorMessagePattern = new RegExp(r'\{(\d+)\}'); 757 static final RegExp _errorMessagePattern = new RegExp(r'\{(\d+)\}');
763 758
764 String makeErrorMessage(ErrorCode error, [List arguments]) { 759 /// Throws an exception that will be caught at the function level, to replace
760 /// the entire function with a throw.
761 emitCompileTimeError(ErrorCode error, [List arguments]) {
765 String message = error.message; 762 String message = error.message;
766 if (arguments != null) { 763 if (arguments != null) {
767 message = message.replaceAllMapped(_errorMessagePattern, (m) { 764 message = message.replaceAllMapped(_errorMessagePattern, (m) {
768 String numberString = m.group(1); 765 String numberString = m.group(1);
769 int index = int.parse(numberString); 766 int index = int.parse(numberString);
770 return arguments[index]; 767 return arguments[index];
771 }); 768 });
772 } 769 }
773 return message; 770 throw new _CompilationError(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));
780 } 771 }
781 772
782 ast.Expression buildThrowAbstractClassInstantiationError(String name) { 773 ast.Expression buildThrowAbstractClassInstantiationError(String name) {
783 return new ast.Throw(new ast.ConstructorInvocation( 774 return new ast.Throw(new ast.ConstructorInvocation(
784 loader.getCoreClassConstructorReference( 775 loader.getCoreClassConstructorReference(
785 'AbstractClassInstantiationError'), 776 'AbstractClassInstantiationError'),
786 new ast.Arguments(<ast.Expression>[new ast.StringLiteral(name)]))); 777 new ast.Arguments(<ast.Expression>[new ast.StringLiteral(name)])));
787 } 778 }
788 779
789 ast.Expression buildThrowFallThroughError() { 780 ast.Expression buildThrowFallThroughError() {
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 scope.buildThis(), 1686 scope.buildThis(),
1696 scope.buildName(node), 1687 scope.buildName(node),
1697 scope.resolveInterfaceGet(element, auxiliary), 1688 scope.resolveInterfaceGet(element, auxiliary),
1698 scope.resolveInterfaceSet(element, auxiliary)); 1689 scope.resolveInterfaceSet(element, auxiliary));
1699 1690
1700 case ElementKind.FUNCTION: 1691 case ElementKind.FUNCTION:
1701 FunctionElement function = element; 1692 FunctionElement function = element;
1702 if (isTopLevelFunction(function)) { 1693 if (isTopLevelFunction(function)) {
1703 return scope.staticAccess(node.name, function); 1694 return scope.staticAccess(node.name, function);
1704 } 1695 }
1705 if (function == function.library.loadLibraryFunction) {
1706 return scope.unsupportedFeature('Deferred loading');
1707 }
1708 return new VariableAccessor(scope.getVariableReference(function)); 1696 return new VariableAccessor(scope.getVariableReference(function));
1709 1697
1710 case ElementKind.LOCAL_VARIABLE: 1698 case ElementKind.LOCAL_VARIABLE:
1711 case ElementKind.PARAMETER: 1699 case ElementKind.PARAMETER:
1712 VariableElement variable = element; 1700 VariableElement variable = element;
1713 var type = identical(node.staticType, variable.type) 1701 var type = identical(node.staticType, variable.type)
1714 ? null 1702 ? null
1715 : scope.buildType(node.staticType); 1703 : scope.buildType(node.staticType);
1716 return new VariableAccessor(scope.getVariableReference(element), type); 1704 return new VariableAccessor(scope.getVariableReference(element), type);
1717 1705
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 ast.Constructor constructor = currentMember; 2730 ast.Constructor constructor = currentMember;
2743 constructor.function = scope.buildFunctionNode(node.parameters, node.body, 2731 constructor.function = scope.buildFunctionNode(node.parameters, node.body,
2744 inferredReturnType: const ast.VoidType())..parent = constructor; 2732 inferredReturnType: const ast.VoidType())..parent = constructor;
2745 handleNativeBody(node.body); 2733 handleNativeBody(node.body);
2746 if (node.body is EmptyFunctionBody && !constructor.isExternal) { 2734 if (node.body is EmptyFunctionBody && !constructor.isExternal) {
2747 var function = constructor.function; 2735 var function = constructor.function;
2748 function.body = new ast.EmptyStatement()..parent = function; 2736 function.body = new ast.EmptyStatement()..parent = function;
2749 } 2737 }
2750 for (var parameter in node.parameters.parameterElements) { 2738 for (var parameter in node.parameters.parameterElements) {
2751 if (parameter is FieldFormalParameterElement) { 2739 if (parameter is FieldFormalParameterElement) {
2752 ast.Initializer initializer; 2740 var initializer = new ast.FieldInitializer(
2753 if (parameter.field == null) { 2741 scope.getMemberReference(parameter.field),
2754 initializer = new ast.LocalInitializer( 2742 new ast.VariableGet(scope.getVariableReference(parameter)));
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 }
2764 constructor.initializers.add(initializer..parent = constructor); 2743 constructor.initializers.add(initializer..parent = constructor);
2765 } 2744 }
2766 } 2745 }
2767 bool hasExplicitConstructorCall = false; 2746 bool hasExplicitConstructorCall = false;
2768 for (var initializer in node.initializers) { 2747 for (var initializer in node.initializers) {
2769 var node = scope.buildInitializer(initializer); 2748 var node = scope.buildInitializer(initializer);
2770 constructor.initializers.add(node..parent = constructor); 2749 constructor.initializers.add(node..parent = constructor);
2771 if (node is ast.SuperInitializer || node is ast.RedirectingInitializer) { 2750 if (node is ast.SuperInitializer || node is ast.RedirectingInitializer) {
2772 hasExplicitConstructorCall = true; 2751 hasExplicitConstructorCall = true;
2773 } 2752 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2986 if (list[i - 1].compareTo(item) == 0) { 2965 if (list[i - 1].compareTo(item) == 0) {
2987 ++deleted; 2966 ++deleted;
2988 } else if (deleted > 0) { 2967 } else if (deleted > 0) {
2989 list[i - deleted] = item; 2968 list[i - deleted] = item;
2990 } 2969 }
2991 } 2970 }
2992 if (deleted > 0) { 2971 if (deleted > 0) {
2993 list.length -= deleted; 2972 list.length -= deleted;
2994 } 2973 }
2995 } 2974 }
OLDNEW
« no previous file with comments | « no previous file | pkg/kernel/lib/analyzer/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698