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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1204733002: dart2js cps: Make Identical a built-in and add Interceptor to Tree IR. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator; 10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator;
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 js.Expression kind = js.number(node.selector.invocationMirrorKind); 586 js.Expression kind = js.number(node.selector.invocationMirrorKind);
587 js.Expression arguments = new js.ArrayInitializer( 587 js.Expression arguments = new js.ArrayInitializer(
588 visitExpressionList(node.arguments)); 588 visitExpressionList(node.arguments));
589 js.Expression argumentNames = new js.ArrayInitializer( 589 js.Expression argumentNames = new js.ArrayInitializer(
590 node.selector.namedArguments.map(js.string).toList(growable: false)); 590 node.selector.namedArguments.map(js.string).toList(growable: false));
591 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, 591 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod,
592 <js.Expression>[name, internalName, kind, arguments, argumentNames]); 592 <js.Expression>[name, internalName, kind, arguments, argumentNames]);
593 } 593 }
594 594
595 @override 595 @override
596 js.Expression visitInterceptor(tree_ir.Interceptor node) {
597 glue.registerUseInterceptorInCodegen();
598 registry.registerSpecializedGetInterceptor(node.interceptedClasses);
599 String helperName = glue.getInterceptorName(node.interceptedClasses);
600 js.Expression globalHolder = glue.getInterceptorLibrary();
601 return js.js('#.#(#)',
602 [globalHolder, helperName, visitExpression(node.input)]);
603 }
604
605 @override
596 js.Expression visitGetField(tree_ir.GetField node) { 606 js.Expression visitGetField(tree_ir.GetField node) {
597 return new js.PropertyAccess.field( 607 return new js.PropertyAccess.field(
598 visitExpression(node.object), 608 visitExpression(node.object),
599 glue.instanceFieldPropertyName(node.field)); 609 glue.instanceFieldPropertyName(node.field));
600 } 610 }
601 611
602 @override 612 @override
603 js.Assignment visitSetField(tree_ir.SetField node) { 613 js.Assignment visitSetField(tree_ir.SetField node) {
604 js.PropertyAccess field = 614 js.PropertyAccess field =
605 new js.PropertyAccess.field( 615 new js.PropertyAccess.field(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 return new js.Binary('<', args[0], args[1]); 720 return new js.Binary('<', args[0], args[1]);
711 case BuiltinOperator.NumLe: 721 case BuiltinOperator.NumLe:
712 return new js.Binary('<=', args[0], args[1]); 722 return new js.Binary('<=', args[0], args[1]);
713 case BuiltinOperator.NumGt: 723 case BuiltinOperator.NumGt:
714 return new js.Binary('>', args[0], args[1]); 724 return new js.Binary('>', args[0], args[1]);
715 case BuiltinOperator.NumGe: 725 case BuiltinOperator.NumGe:
716 return new js.Binary('>=', args[0], args[1]); 726 return new js.Binary('>=', args[0], args[1]);
717 case BuiltinOperator.StringConcatenate: 727 case BuiltinOperator.StringConcatenate:
718 if (args.isEmpty) return js.string(''); 728 if (args.isEmpty) return js.string('');
719 return args.reduce((e1,e2) => new js.Binary('+', e1, e2)); 729 return args.reduce((e1,e2) => new js.Binary('+', e1, e2));
730 case BuiltinOperator.Identical:
731 registry.registerStaticInvocation(glue.identicalFunction);
732 return buildStaticHelperInvocation(glue.identicalFunction, args);
720 case BuiltinOperator.StrictEq: 733 case BuiltinOperator.StrictEq:
721 return new js.Binary('===', args[0], args[1]); 734 return new js.Binary('===', args[0], args[1]);
722 case BuiltinOperator.StrictNeq: 735 case BuiltinOperator.StrictNeq:
723 return new js.Binary('!==', args[0], args[1]); 736 return new js.Binary('!==', args[0], args[1]);
724 case BuiltinOperator.LooseEq: 737 case BuiltinOperator.LooseEq:
725 return new js.Binary('==', args[0], args[1]); 738 return new js.Binary('==', args[0], args[1]);
726 case BuiltinOperator.LooseNeq: 739 case BuiltinOperator.LooseNeq:
727 return new js.Binary('!=', args[0], args[1]); 740 return new js.Binary('!=', args[0], args[1]);
728 case BuiltinOperator.IsFalsy: 741 case BuiltinOperator.IsFalsy:
729 return new js.Prefix('!', args[0]); 742 return new js.Prefix('!', args[0]);
730 case BuiltinOperator.IsNumber: 743 case BuiltinOperator.IsNumber:
731 return js.js("typeof # === 'number'", args); 744 return js.js("typeof # === 'number'", args);
732 case BuiltinOperator.IsNotNumber: 745 case BuiltinOperator.IsNotNumber:
733 return js.js("typeof # !== 'number'", args); 746 return js.js("typeof # !== 'number'", args);
734 case BuiltinOperator.IsFloor: 747 case BuiltinOperator.IsFloor:
735 return js.js("Math.floor(#) === #", args); 748 return js.js("Math.floor(#) === #", args);
736 case BuiltinOperator.IsNumberAndFloor: 749 case BuiltinOperator.IsNumberAndFloor:
737 return js.js("typeof # === 'number' && Math.floor(#) === #", args); 750 return js.js("typeof # === 'number' && Math.floor(#) === #", args);
738 } 751 }
739 } 752 }
740 753
741 visitFunctionExpression(tree_ir.FunctionExpression node) { 754 visitFunctionExpression(tree_ir.FunctionExpression node) {
742 // FunctionExpressions are currently unused. 755 // FunctionExpressions are currently unused.
743 // We might need them if we want to emit raw JS nested functions. 756 // We might need them if we want to emit raw JS nested functions.
744 throw 'FunctionExpressions should not be used'; 757 throw 'FunctionExpressions should not be used';
745 } 758 }
746 } 759 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698