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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1288013002: dart2js cps: Handle native functions, getters, and setters. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments. Created 5 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 | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/dart_types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
index 79731e783359e9743f581d5bdabe3286c9cfa4c6..ba89171709bd112779f0bb4739d28d7088476c4b 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
@@ -401,17 +401,39 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
return null;
}
+ static final RegExp nativeRedirectionRegExp =
+ new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$');
+
// Build(Return(e), C) = C'[InvokeContinuation(return, x)]
// where (C', x) = Build(e, C)
//
// Return without a subexpression is translated as if it were return null.
- ir.Primitive visitReturn(ast.Return node) {
+ visitReturn(ast.Return node) {
assert(irBuilder.isOpen);
- assert(invariant(node, node.beginToken.value != 'native'));
- irBuilder.buildReturn(
- value: build(node.expression),
- sourceInformation: sourceInformationBuilder.buildReturn(node));
- return null;
+ SourceInformation source = sourceInformationBuilder.buildReturn(node);
+ if (node.beginToken.value == 'native') {
+ FunctionElement function = irBuilder.state.currentElement;
+ assert(function.isNative);
+ ast.Node nativeBody = node.expression;
+ if (nativeBody != null) {
+ ast.LiteralString jsCode = nativeBody.asLiteralString();
+ String javaScriptCode = jsCode.dartString.slowToString();
+ assert(invariant(nativeBody,
+ !nativeRedirectionRegExp.hasMatch(javaScriptCode),
+ message: "Deprecated syntax, use @JSName('name') instead."));
+ assert(invariant(nativeBody,
+ function.functionSignature.parameterCount == 0,
+ message: 'native "..." syntax is restricted to '
+ 'functions with zero parameters.'));
+ irBuilder.buildNativeFunctionBody(function, javaScriptCode);
+ } else {
+ irBuilder.buildRedirectingNativeFunctionBody(function, source);
+ }
+ } else {
+ irBuilder.buildReturn(
+ value: build(node.expression),
+ sourceInformation: source);
+ }
}
visitSwitchStatement(ast.SwitchStatement node) {
@@ -2281,12 +2303,23 @@ class GlobalProgramInformation {
DartType unaliasType(DartType type) => type.unalias(_compiler);
TypeMask getTypeMaskForForeign(NativeBehavior behavior) {
+ if (behavior == null) {
+ return _backend.dynamicType;
+ }
return TypeMaskFactory.fromNativeBehavior(behavior, _compiler);
}
FieldElement locateSingleField(Selector selector, TypeMask type) {
return _compiler.world.locateSingleField(selector, type);
}
+
+ Element get closureConverter {
+ return _backend.getClosureConverter();
+ }
+
+ void addNativeMethod(FunctionElement function) {
+ _backend.emitter.nativeEmitter.nativeMethods.add(function);
+ }
}
/// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder].
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/dart_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698