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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart

Issue 333823005: Add support for ! and != to the new IR builder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; 5 library dart2js.ir_builder;
6 6
7 import 'ir_nodes.dart' as ir; 7 import 'ir_nodes.dart' as ir;
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../dart2jslib.dart'; 9 import '../dart2jslib.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 Selector selector = elements.getSelector(node); 943 Selector selector = elements.getSelector(node);
944 assert(selector.kind == SelectorKind.GETTER); 944 assert(selector.kind == SelectorKind.GETTER);
945 ir.InvokeStatic invoke = new ir.InvokeStatic(element, selector, k, []); 945 ir.InvokeStatic invoke = new ir.InvokeStatic(element, selector, k, []);
946 add(new ir.LetCont(k, invoke)); 946 add(new ir.LetCont(k, invoke));
947 return v; 947 return v;
948 } else { 948 } else {
949 return giveup(); // TODO: figure out what's missing here 949 return giveup(); // TODO: figure out what's missing here
950 } 950 }
951 } 951 }
952 952
953 ir.Primitive translateNot(ir.Primitive condition) {
Kevin Millikin (Google) 2014/06/20 09:18:14 Maybe "translate" is the wrong name, it's not tran
sigurdm 2014/06/23 08:08:57 Much better name, thanks
954 // ! e is translated as e ? false : true
955
956 // Add a continuation parameter for the result of the expression.
957 ir.Parameter resultParameter = new ir.Parameter(null);
958
959 ir.Continuation joinContinuation = new ir.Continuation([resultParameter]);
960 ir.Continuation thenContinuation = new ir.Continuation([]);
961 ir.Continuation elseContinuation = new ir.Continuation([]);
962
963 ir.Constant trueConstant =
964 new ir.Constant(constantSystem.createBool(true));
965 ir.Constant falseConstant =
966 new ir.Constant(constantSystem.createBool(false));
967
968 thenContinuation.body = new ir.LetPrim(falseConstant)
969 ..plug(new ir.InvokeContinuation(joinContinuation, [falseConstant]));
970 elseContinuation.body = new ir.LetPrim(trueConstant)
971 ..plug(new ir.InvokeContinuation(joinContinuation, [trueConstant]));
972
973 add(new ir.LetCont(joinContinuation,
974 new ir.LetCont(thenContinuation,
975 new ir.LetCont(elseContinuation,
976 new ir.Branch(new ir.IsTrue(condition),
977 thenContinuation,
978 elseContinuation)))));
979 return resultParameter;
980 }
981
953 ir.Primitive translateLogicalOperator(ast.Operator op, 982 ir.Primitive translateLogicalOperator(ast.Operator op,
954 ast.Expression left, 983 ast.Expression left,
955 ast.Expression right) { 984 ast.Expression right) {
956 // e0 && e1 is translated as if e0 ? (e1 == true) : false. 985 // e0 && e1 is translated as if e0 ? (e1 == true) : false.
957 // e0 || e1 is translated as if e0 ? true : (e1 == true). 986 // e0 || e1 is translated as if e0 ? true : (e1 == true).
958 // The translation must convert both e0 and e1 to booleans and handle 987 // The translation must convert both e0 and e1 to booleans and handle
959 // local variable assignments in e1. 988 // local variable assignments in e1.
960 989
961 ir.Primitive leftValue = visit(left); 990 ir.Primitive leftValue = visit(left);
962 IrBuilder rightBuilder = new IrBuilder.delimited(this); 991 IrBuilder rightBuilder = new IrBuilder.delimited(this);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 ast.Operator op = node.selector; 1073 ast.Operator op = node.selector;
1045 if (isUserDefinableOperator(op.source)) { 1074 if (isUserDefinableOperator(op.source)) {
1046 return visitDynamicSend(node); 1075 return visitDynamicSend(node);
1047 } 1076 }
1048 if (op.source == '&&' || op.source == '||') { 1077 if (op.source == '&&' || op.source == '||') {
1049 assert(node.receiver != null); 1078 assert(node.receiver != null);
1050 assert(!node.arguments.isEmpty); 1079 assert(!node.arguments.isEmpty);
1051 assert(node.arguments.tail.isEmpty); 1080 assert(node.arguments.tail.isEmpty);
1052 return translateLogicalOperator(op, node.receiver, node.arguments.head); 1081 return translateLogicalOperator(op, node.receiver, node.arguments.head);
1053 } 1082 }
1083 if (op.source == "!") {
1084 assert(node.receiver != null);
1085 assert(node.arguments.isEmpty);
1086 return translateNot(visit(node.receiver));
1087 }
1088 if (op.source == "!=") {
1089 assert(node.receiver != null);
1090 assert(!node.arguments.isEmpty);
1091 assert(node.arguments.tail.isEmpty);
1092 return translateNot(visitDynamicSend(node));
1093 }
1054 return giveup(); 1094 return giveup();
1055 } 1095 }
1056 1096
1057 // Build(StaticSend(f, arguments), C) = C[C'[InvokeStatic(f, xs)]] 1097 // Build(StaticSend(f, arguments), C) = C[C'[InvokeStatic(f, xs)]]
1058 // where (C', xs) = arguments.fold(Build, C) 1098 // where (C', xs) = arguments.fold(Build, C)
1059 ir.Primitive visitStaticSend(ast.Send node) { 1099 ir.Primitive visitStaticSend(ast.Send node) {
1060 assert(isOpen); 1100 assert(isOpen);
1061 Element element = elements[node]; 1101 Element element = elements[node];
1062 // TODO(lry): support constructors / factory calls. 1102 // TODO(lry): support constructors / factory calls.
1063 if (element.isConstructor) return giveup(); 1103 if (element.isConstructor) return giveup();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 bool visitType(DartType type, Null _) => false; 1333 bool visitType(DartType type, Null _) => false;
1294 1334
1295 bool visitDynamicType(DynamicType type, Null _) => true; 1335 bool visitDynamicType(DynamicType type, Null _) => true;
1296 1336
1297 bool visitVoidType(VoidType type, Null _) => true; 1337 bool visitVoidType(VoidType type, Null _) => true;
1298 1338
1299 // Currently, InterfaceType and TypedefType are supported so long as they 1339 // Currently, InterfaceType and TypedefType are supported so long as they
1300 // do not have type parameters. They are subclasses of GenericType. 1340 // do not have type parameters. They are subclasses of GenericType.
1301 bool visitGenericType(GenericType type, Null _) => !type.isGeneric; 1341 bool visitGenericType(GenericType type, Null _) => !type.isGeneric;
1302 } 1342 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698