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

Unified 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, 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 75547da496dc779ee7908395b4493269eeebee09..4a52308b1f9f52b8433af9a7ea311a7a18fca754 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;
+ }
+
+ 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