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

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

Issue 2995293002: Redo "dart2js-kernel: implement native static methods" (Closed)
Patch Set: Fix analyzer warning Created 3 years, 3 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 | tests/compiler/dart2js_native/dart2js_native.status » ('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 4
5 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry; 9 import '../common/codegen.dart' show CodegenRegistry;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // `sourceInformationBuilder.buildIf(?)`. 712 // `sourceInformationBuilder.buildIf(?)`.
713 ); 713 );
714 } 714 }
715 } 715 }
716 functionNode.body.accept(this); 716 functionNode.body.accept(this);
717 closeFunction(); 717 closeFunction();
718 } 718 }
719 719
720 /// Builds a SSA graph for FunctionNodes of external methods. 720 /// Builds a SSA graph for FunctionNodes of external methods.
721 void buildExternalFunctionNode(ir.FunctionNode functionNode) { 721 void buildExternalFunctionNode(ir.FunctionNode functionNode) {
722 assert(functionNode.body == null);
722 openFunction(functionNode); 723 openFunction(functionNode);
723 ir.TreeNode parent = functionNode.parent; 724 ir.TreeNode parent = functionNode.parent;
724 if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) { 725 if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) {
725 _addClassTypeVariablesIfNeeded(parent); 726 _addClassTypeVariablesIfNeeded(parent);
726 } 727 }
727 // TODO(sra): Generate conversion of Function typed arguments to JavaScript 728
728 // functions. 729 if (closedWorld.nativeData.isNativeMember(targetElement)) {
729 // TODO(sra): Invoke native method. 730 String nativeName;
730 assert(functionNode.body == null); 731 if (closedWorld.nativeData.hasFixedBackendName(targetElement)) {
732 nativeName = closedWorld.nativeData.getFixedBackendName(targetElement);
733 } else {
734 nativeName = targetElement.name;
735 }
736
737 String templateReceiver = '';
738 List<String> templateArguments = <String>[];
739 List<HInstruction> inputs = <HInstruction>[];
740 if (targetElement.isInstanceMember) {
741 templateReceiver = '#.';
742 inputs.add(localsHandler.readThis());
743 }
744
745 for (ir.VariableDeclaration param in functionNode.positionalParameters) {
746 templateArguments.add('#');
747 Local local = localsMap.getLocalVariable(param);
748 // Convert Dart function to JavaScript function.
749 HInstruction argument = localsHandler.readLocal(local);
750 ir.DartType type = param.type;
751 if (type is ir.FunctionType) {
752 int arity = type.positionalParameters.length;
753 _pushStaticInvocation(
754 _commonElements.closureConverter,
755 [argument, graph.addConstantInt(arity, closedWorld)],
756 commonMasks.dynamicType);
757 argument = pop();
758 }
759 inputs.add(argument);
760 }
761
762 String arguments = templateArguments.join(',');
763
764 // TODO(sra): Use declared type or NativeBehavior type.
765 TypeMask typeMask = commonMasks.dynamicType;
766 String template;
767 if (targetElement.isGetter) {
768 template = '${templateReceiver}$nativeName';
769 } else if (targetElement.isSetter) {
770 template = '${templateReceiver}$nativeName = ${arguments}';
771 } else {
772 template = '${templateReceiver}$nativeName(${arguments})';
773 }
774
775 push(new HForeignCode(
776 js.js.uncachedExpressionTemplate(template), typeMask, inputs,
777 effects: new SideEffects()));
778 // TODO(johnniwinther): Provide source information.
779 HInstruction value = pop();
780 if (targetElement.isSetter) {
781 value = graph.addConstantNull(closedWorld);
782 }
783 close(new HReturn(value, null)).addSuccessor(graph.exit);
784 }
785 // TODO(sra): Handle JS-interop methods.
731 closeFunction(); 786 closeFunction();
732 } 787 }
733 788
734 void addImplicitInstantiation(DartType type) { 789 void addImplicitInstantiation(DartType type) {
735 if (type != null) { 790 if (type != null) {
736 currentImplicitInstantiations.add(type); 791 currentImplicitInstantiations.add(type);
737 } 792 }
738 } 793 }
739 794
740 void removeImplicitInstantiation(DartType type) { 795 void removeImplicitInstantiation(DartType type) {
(...skipping 2939 matching lines...) Expand 10 before | Expand all | Expand 10 after
3680 enterBlock.setBlockFlow( 3735 enterBlock.setBlockFlow(
3681 new HTryBlockInformation( 3736 new HTryBlockInformation(
3682 kernelBuilder.wrapStatementGraph(bodyGraph), 3737 kernelBuilder.wrapStatementGraph(bodyGraph),
3683 exception, 3738 exception,
3684 kernelBuilder.wrapStatementGraph(catchGraph), 3739 kernelBuilder.wrapStatementGraph(catchGraph),
3685 kernelBuilder.wrapStatementGraph(finallyGraph)), 3740 kernelBuilder.wrapStatementGraph(finallyGraph)),
3686 exitBlock); 3741 exitBlock);
3687 kernelBuilder.inTryStatement = previouslyInTryStatement; 3742 kernelBuilder.inTryStatement = previouslyInTryStatement;
3688 } 3743 }
3689 } 3744 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js_native/dart2js_native.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698