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

Unified Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2997253002: dart2js-kernel: implement native static methods (Closed)
Patch Set: Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js_native/dart2js_native.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/builder_kernel.dart
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index 2da1e5811649290fd0459f5525fcb02b4d3595f5..d501e09deaabe408fd8ef45f1b861f2c9f22abfe 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -719,15 +719,70 @@ class KernelSsaGraphBuilder extends ir.Visitor
/// Builds a SSA graph for FunctionNodes of external methods.
void buildExternalFunctionNode(ir.FunctionNode functionNode) {
+ assert(functionNode.body == null);
openFunction(functionNode);
ir.TreeNode parent = functionNode.parent;
if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) {
_addClassTypeVariablesIfNeeded(parent);
}
- // TODO(sra): Generate conversion of Function typed arguments to JavaScript
- // functions.
- // TODO(sra): Invoke native method.
- assert(functionNode.body == null);
+
+ if (closedWorld.nativeData.isNativeMember(targetElement)) {
+ String nativeName;
+ if (closedWorld.nativeData.hasFixedBackendName(targetElement)) {
+ nativeName = closedWorld.nativeData.getFixedBackendName(targetElement);
+ } else {
+ nativeName = targetElement.name.name;
+ }
+
+ String templateReceiver = '';
+ List<String> templateArguments = <String>[];
+ List<HInstruction> inputs = <HInstruction>[];
+ if (targetElement.isInstanceMember) {
+ templateReceiver = '#.';
+ inputs.add(localsHandler.readThis());
+ }
+
+ for (ir.VariableDeclaration param in functionNode.positionalParameters) {
+ templateArguments.add('#');
+ Local local = localsMap.getLocalVariable(param);
+ // Convert Dart function to JavaScript function.
+ HInstruction argument = localsHandler.readLocal(local);
+ ir.DartType type = param.type;
+ if (type is ir.FunctionType) {
+ int arity = type.positionalParameters.length;
+ _pushStaticInvocation(
+ _commonElements.closureConverter,
+ [argument, graph.addConstantInt(arity, closedWorld)],
+ commonMasks.dynamicType);
+ argument = pop();
+ }
+ inputs.add(argument);
+ }
+
+ String arguments = templateArguments.join(',');
+
+ // TODO(sra): Use declared type or NativeBehavior type.
+ TypeMask typeMask = commonMasks.dynamicType;
+ String template;
+ if (targetElement.isGetter) {
+ template = '${templateReceiver}$nativeName';
+ } else if (targetElement.isSetter) {
+ template = '${templateReceiver}$nativeName = ${arguments}';
+ } else {
+ template = '${templateReceiver}$nativeName(${arguments})';
+ }
+
+ push(new HForeignCode(
+ js.js.uncachedExpressionTemplate(template), typeMask, inputs,
+ effects: new SideEffects()));
+ // TODO(johnniwinther): Provide source information.
+ HInstruction value = pop();
+ if (targetElement.isSetter) {
+ value = graph.addConstantNull(closedWorld);
+ }
+ close(new HReturn(value, null)).addSuccessor(graph.exit);
+ }
+ // TODO(sra): Handle JS-interop methods.
closeFunction();
}
« 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