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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1408043002: Move native and js interop properties from the element model to the JS backend (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart2js.ir_builder_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closurelib; 7 import '../closure.dart' as closurelib;
8 import '../closure.dart' hide ClosureScope; 8 import '../closure.dart' hide ClosureScope;
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart' show 10 import '../common/names.dart' show
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 433
434 // Build(Return(e), C) = C'[InvokeContinuation(return, x)] 434 // Build(Return(e), C) = C'[InvokeContinuation(return, x)]
435 // where (C', x) = Build(e, C) 435 // where (C', x) = Build(e, C)
436 // 436 //
437 // Return without a subexpression is translated as if it were return null. 437 // Return without a subexpression is translated as if it were return null.
438 visitReturn(ast.Return node) { 438 visitReturn(ast.Return node) {
439 assert(irBuilder.isOpen); 439 assert(irBuilder.isOpen);
440 SourceInformation source = sourceInformationBuilder.buildReturn(node); 440 SourceInformation source = sourceInformationBuilder.buildReturn(node);
441 if (node.beginToken.value == 'native') { 441 if (node.beginToken.value == 'native') {
442 FunctionElement function = irBuilder.state.currentElement; 442 FunctionElement function = irBuilder.state.currentElement;
443 assert(function.isNative); 443 assert(compiler.backend.isNative(function));
444 ast.Node nativeBody = node.expression; 444 ast.Node nativeBody = node.expression;
445 if (nativeBody != null) { 445 if (nativeBody != null) {
446 ast.LiteralString jsCode = nativeBody.asLiteralString(); 446 ast.LiteralString jsCode = nativeBody.asLiteralString();
447 String javaScriptCode = jsCode.dartString.slowToString(); 447 String javaScriptCode = jsCode.dartString.slowToString();
448 assert(invariant(nativeBody, 448 assert(invariant(nativeBody,
449 !nativeRedirectionRegExp.hasMatch(javaScriptCode), 449 !nativeRedirectionRegExp.hasMatch(javaScriptCode),
450 message: "Deprecated syntax, use @JSName('name') instead.")); 450 message: "Deprecated syntax, use @JSName('name') instead."));
451 assert(invariant(nativeBody, 451 assert(invariant(nativeBody,
452 function.functionSignature.parameterCount == 0, 452 function.functionSignature.parameterCount == 0,
453 message: 'native "..." syntax is restricted to ' 453 message: 'native "..." syntax is restricted to '
454 'functions with zero parameters.')); 454 'functions with zero parameters.'));
455 irBuilder.buildNativeFunctionBody(function, javaScriptCode); 455 irBuilder.buildNativeFunctionBody(function, javaScriptCode);
456 } else { 456 } else {
457 irBuilder.buildRedirectingNativeFunctionBody(function, source); 457 JavaScriptBackend backend = compiler.backend;
458 String name = backend.getFixedBackendName(function);
459 irBuilder.buildRedirectingNativeFunctionBody(function, name, source);
458 } 460 }
459 } else { 461 } else {
460 irBuilder.buildReturn( 462 irBuilder.buildReturn(
461 value: build(node.expression), 463 value: build(node.expression),
462 sourceInformation: source); 464 sourceInformation: source);
463 } 465 }
464 } 466 }
465 467
466 visitSwitchStatement(ast.SwitchStatement node) { 468 visitSwitchStatement(ast.SwitchStatement node) {
467 assert(irBuilder.isOpen); 469 assert(irBuilder.isOpen);
(...skipping 2317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 // The initial value of all fields are now bound in [fieldValues]. 2787 // The initial value of all fields are now bound in [fieldValues].
2786 2788
2787 // --- Create the object --- 2789 // --- Create the object ---
2788 // Get the initial field values in the canonical order. 2790 // Get the initial field values in the canonical order.
2789 List<ir.Primitive> instanceArguments = <ir.Primitive>[]; 2791 List<ir.Primitive> instanceArguments = <ir.Primitive>[];
2790 classElement.forEachInstanceField((ClassElement c, FieldElement field) { 2792 classElement.forEachInstanceField((ClassElement c, FieldElement field) {
2791 ir.Primitive value = fieldValues[field]; 2793 ir.Primitive value = fieldValues[field];
2792 if (value != null) { 2794 if (value != null) {
2793 instanceArguments.add(value); 2795 instanceArguments.add(value);
2794 } else { 2796 } else {
2795 assert(Elements.isNativeOrExtendsNative(c)); 2797 assert(backend.isNativeOrExtendsNative(c));
2796 // Native fields are initialized elsewhere. 2798 // Native fields are initialized elsewhere.
2797 } 2799 }
2798 }, includeSuperAndInjectedMembers: true); 2800 }, includeSuperAndInjectedMembers: true);
2799 2801
2800 ir.Primitive instance = new ir.CreateInstance( 2802 ir.Primitive instance = new ir.CreateInstance(
2801 classElement, 2803 classElement,
2802 instanceArguments, 2804 instanceArguments,
2803 typeInformation, 2805 typeInformation,
2804 constructor.hasNode 2806 constructor.hasNode
2805 ? sourceInformationBuilder.buildCreate(constructor.node) 2807 ? sourceInformationBuilder.buildCreate(constructor.node)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2850 assert(constructor == elements.analyzedElement); 2852 assert(constructor == elements.analyzedElement);
2851 ClassElement enclosingClass = constructor.enclosingClass.implementation; 2853 ClassElement enclosingClass = constructor.enclosingClass.implementation;
2852 // Evaluate declaration-site field initializers, unless this constructor 2854 // Evaluate declaration-site field initializers, unless this constructor
2853 // redirects to another using a `this()` initializer. In that case, these 2855 // redirects to another using a `this()` initializer. In that case, these
2854 // will be initialized by the effective target constructor. 2856 // will be initialized by the effective target constructor.
2855 if (!constructor.isRedirectingGenerative) { 2857 if (!constructor.isRedirectingGenerative) {
2856 enclosingClass.forEachInstanceField((ClassElement c, FieldElement field) { 2858 enclosingClass.forEachInstanceField((ClassElement c, FieldElement field) {
2857 if (field.initializer != null) { 2859 if (field.initializer != null) {
2858 fieldValues[field] = inlineExpression(field, field.initializer); 2860 fieldValues[field] = inlineExpression(field, field.initializer);
2859 } else { 2861 } else {
2860 if (Elements.isNativeOrExtendsNative(c)) { 2862 if (backend.isNativeOrExtendsNative(c)) {
2861 // Native field is initialized elsewhere. 2863 // Native field is initialized elsewhere.
2862 } else { 2864 } else {
2863 // Fields without an initializer default to null. 2865 // Fields without an initializer default to null.
2864 // This value will be overwritten below if an initializer is found. 2866 // This value will be overwritten below if an initializer is found.
2865 fieldValues[field] = irBuilder.buildNullConstant(); 2867 fieldValues[field] = irBuilder.buildNullConstant();
2866 } 2868 }
2867 } 2869 }
2868 }); 2870 });
2869 } 2871 }
2870 // If this is a mixin constructor, it does not have its own parameter list 2872 // If this is a mixin constructor, it does not have its own parameter list
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
3576 if (compiler.backend.isForeign(function)) { 3578 if (compiler.backend.isForeign(function)) {
3577 return handleForeignCode(node, function, argumentList, callStructure); 3579 return handleForeignCode(node, function, argumentList, callStructure);
3578 } else { 3580 } else {
3579 return irBuilder.buildStaticFunctionInvocation(function, callStructure, 3581 return irBuilder.buildStaticFunctionInvocation(function, callStructure,
3580 translateStaticArguments(argumentList, function, callStructure), 3582 translateStaticArguments(argumentList, function, callStructure),
3581 sourceInformation: 3583 sourceInformation:
3582 sourceInformationBuilder.buildCall(node, node.selector)); 3584 sourceInformationBuilder.buildCall(node, node.selector));
3583 } 3585 }
3584 } 3586 }
3585 } 3587 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/type_propagation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698