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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 2637533003: dart2js-kernel: Call generative constructor body functions (Closed)
Patch Set: fix analyzer warning 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 | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/ssa/builder_kernel.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) 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 import 'dart:collection'; 5 import 'dart:collection';
6 6
7 import 'package:js_runtime/shared/embedded_names.dart'; 7 import 'package:js_runtime/shared/embedded_names.dart';
8 8
9 import '../closure.dart'; 9 import '../closure.dart';
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 break; 791 break;
792 } 792 }
793 } 793 }
794 794
795 closeAndGotoExit(new HReturn( 795 closeAndGotoExit(new HReturn(
796 value, sourceInformationBuilder.buildReturn(sourceInfoNode))); 796 value, sourceInformationBuilder.buildReturn(sourceInfoNode)));
797 return closeFunction(); 797 return closeFunction();
798 } 798 }
799 799
800 /** 800 /**
801 * Returns the constructor body associated with the given constructor or
802 * creates a new constructor body, if none can be found.
803 *
804 * Returns [:null:] if the constructor does not have a body.
805 */
806 ConstructorBodyElement getConstructorBody(
807 ResolvedAst constructorResolvedAst) {
808 ConstructorElement constructor =
809 constructorResolvedAst.element.implementation;
810 assert(constructor.isGenerativeConstructor);
811 if (constructorResolvedAst.kind != ResolvedAstKind.PARSED) return null;
812
813 ast.FunctionExpression node = constructorResolvedAst.node;
814 // If we know the body doesn't have any code, we don't generate it.
815 if (!node.hasBody) return null;
816 if (node.hasEmptyBody) return null;
817 ClassElement classElement = constructor.enclosingClass;
818 ConstructorBodyElement bodyElement;
819 classElement.forEachBackendMember((Element backendMember) {
820 if (backendMember.isGenerativeConstructorBody) {
821 ConstructorBodyElement body = backendMember;
822 if (body.constructor == constructor) {
823 // TODO(kasperl): Find a way of stopping the iteration
824 // through the backend members.
825 bodyElement = backendMember;
826 }
827 }
828 });
829 if (bodyElement == null) {
830 bodyElement =
831 new ConstructorBodyElementX(constructorResolvedAst, constructor);
832 classElement.addBackendMember(bodyElement);
833
834 if (constructor.isPatch) {
835 // Create origin body element for patched constructors.
836 ConstructorBodyElementX patch = bodyElement;
837 ConstructorBodyElementX origin = new ConstructorBodyElementX(
838 constructorResolvedAst, constructor.origin);
839 origin.applyPatch(patch);
840 classElement.origin.addBackendMember(bodyElement.origin);
841 }
842 }
843 assert(bodyElement.isGenerativeConstructorBody);
844 return bodyElement;
845 }
846
847 /**
848 * This method sets up the local state of the builder for inlining [function]. 801 * This method sets up the local state of the builder for inlining [function].
849 * The arguments of the function are inserted into the [localsHandler]. 802 * The arguments of the function are inserted into the [localsHandler].
850 * 803 *
851 * When inlining a function, [:return:] statements are not emitted as 804 * When inlining a function, [:return:] statements are not emitted as
852 * [HReturn] instructions. Instead, the value of a synthetic element is 805 * [HReturn] instructions. Instead, the value of a synthetic element is
853 * updated in the [localsHandler]. This function creates such an element and 806 * updated in the [localsHandler]. This function creates such an element and
854 * stores it in the [returnLocal] field. 807 * stores it in the [returnLocal] field.
855 */ 808 */
856 void setupStateForInlining( 809 void setupStateForInlining(
857 FunctionElement function, List<HInstruction> compiledArguments, 810 FunctionElement function, List<HInstruction> compiledArguments,
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 for (int i = 0; i < fields.length; i++) { 1297 for (int i = 0; i < fields.length; i++) {
1345 add(new HFieldSet(fields[i], newObject, constructorArguments[i])); 1298 add(new HFieldSet(fields[i], newObject, constructorArguments[i]));
1346 } 1299 }
1347 } 1300 }
1348 removeInlinedInstantiation(type); 1301 removeInlinedInstantiation(type);
1349 1302
1350 // Generate calls to the constructor bodies. 1303 // Generate calls to the constructor bodies.
1351 HInstruction interceptor = null; 1304 HInstruction interceptor = null;
1352 for (int index = constructorResolvedAsts.length - 1; index >= 0; index--) { 1305 for (int index = constructorResolvedAsts.length - 1; index >= 0; index--) {
1353 ResolvedAst constructorResolvedAst = constructorResolvedAsts[index]; 1306 ResolvedAst constructorResolvedAst = constructorResolvedAsts[index];
1354 ConstructorBodyElement body = getConstructorBody(constructorResolvedAst); 1307 ConstructorBodyElement body =
1308 ConstructorBodyElementX.createFromResolvedAst(constructorResolvedAst);
1355 if (body == null) continue; 1309 if (body == null) continue;
1356 1310
1357 List bodyCallInputs = <HInstruction>[]; 1311 List bodyCallInputs = <HInstruction>[];
1358 if (isNativeUpgradeFactory) { 1312 if (isNativeUpgradeFactory) {
1359 if (interceptor == null) { 1313 if (interceptor == null) {
1360 ConstantValue constant = new InterceptorConstantValue(classElement); 1314 ConstantValue constant = new InterceptorConstantValue(classElement);
1361 interceptor = graph.addConstant(constant, closedWorld); 1315 interceptor = graph.addConstant(constant, closedWorld);
1362 } 1316 }
1363 bodyCallInputs.add(interceptor); 1317 bodyCallInputs.add(interceptor);
1364 } 1318 }
(...skipping 5407 matching lines...) Expand 10 before | Expand all | Expand 10 after
6772 this.oldReturnLocal, 6726 this.oldReturnLocal,
6773 this.oldReturnType, 6727 this.oldReturnType,
6774 this.oldResolvedAst, 6728 this.oldResolvedAst,
6775 this.oldStack, 6729 this.oldStack,
6776 this.oldLocalsHandler, 6730 this.oldLocalsHandler,
6777 this.inTryStatement, 6731 this.inTryStatement,
6778 this.allFunctionsCalledOnce, 6732 this.allFunctionsCalledOnce,
6779 this.oldElementInferenceResults) 6733 this.oldElementInferenceResults)
6780 : super(function); 6734 : super(function);
6781 } 6735 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/ssa/builder_kernel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698