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

Side by Side Diff: pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart

Issue 1175973005: dart2js cps: Introduce some built-in operators in type propagation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Status files 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 tree_ir_nodes; 5 library tree_ir_nodes;
6 6
7 import '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' as values; 8 import '../constants/values.dart' as values;
9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; 9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType;
10 import '../elements/elements.dart'; 10 import '../elements/elements.dart';
11 import '../io/source_information.dart' show SourceInformation; 11 import '../io/source_information.dart' show SourceInformation;
12 import '../universe/universe.dart' show Selector; 12 import '../universe/universe.dart' show Selector;
13 13
14 import '../cps_ir/builtin_operator.dart';
15 export '../cps_ir/builtin_operator.dart';
16
14 // The Tree language is the target of translation out of the CPS-based IR. 17 // The Tree language is the target of translation out of the CPS-based IR.
15 // 18 //
16 // The translation from CPS to Dart consists of several stages. Among the 19 // The translation from CPS to Dart consists of several stages. Among the
17 // stages are translation to direct style, translation out of SSA, eliminating 20 // stages are translation to direct style, translation out of SSA, eliminating
18 // unnecessary names, recognizing high-level control constructs. Combining 21 // unnecessary names, recognizing high-level control constructs. Combining
19 // these separate concerns is complicated and the constraints of the CPS-based 22 // these separate concerns is complicated and the constraints of the CPS-based
20 // language do not permit a multi-stage translation. 23 // language do not permit a multi-stage translation.
21 // 24 //
22 // For that reason, CPS is translated to the direct-style language Tree. 25 // For that reason, CPS is translated to the direct-style language Tree.
23 // Translation out of SSA, unnaming, and control-flow, as well as 'instruction 26 // Translation out of SSA, unnaming, and control-flow, as well as 'instruction
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 {bool this.isTypeTest}); 340 {bool this.isTypeTest});
338 341
339 accept(ExpressionVisitor visitor) => visitor.visitTypeOperator(this); 342 accept(ExpressionVisitor visitor) => visitor.visitTypeOperator(this);
340 accept1(ExpressionVisitor1 visitor, arg) { 343 accept1(ExpressionVisitor1 visitor, arg) {
341 return visitor.visitTypeOperator(this, arg); 344 return visitor.visitTypeOperator(this, arg);
342 } 345 }
343 346
344 String get operator => isTypeTest ? 'is' : 'as'; 347 String get operator => isTypeTest ? 'is' : 'as';
345 } 348 }
346 349
350 /**
351 * Apply a built-in operator.
352 *
353 * It must be known that the arguments have the proper types.
354 * Null is not a valid argument to any of the built-in operators.
355 */
356 class ApplyBuiltinOperator extends Expression {
357 BuiltinOperator operator;
358 List<Expression> arguments;
359
360 ApplyBuiltinOperator(this.operator, this.arguments);
361
362 accept(ExpressionVisitor visitor) {
363 return visitor.visitApplyBuiltinOperator(this);
364 }
365 accept1(ExpressionVisitor1 visitor, arg) {
366 return visitor.visitApplyBuiltinOperator(this, arg);
367 }
368 }
369
347 /// A conditional expression. 370 /// A conditional expression.
348 class Conditional extends Expression { 371 class Conditional extends Expression {
349 Expression condition; 372 Expression condition;
350 Expression thenExpression; 373 Expression thenExpression;
351 Expression elseExpression; 374 Expression elseExpression;
352 375
353 Conditional(this.condition, this.thenExpression, this.elseExpression); 376 Conditional(this.condition, this.thenExpression, this.elseExpression);
354 377
355 accept(ExpressionVisitor visitor) => visitor.visitConditional(this); 378 accept(ExpressionVisitor visitor) => visitor.visitConditional(this);
356 accept1(ExpressionVisitor1 visitor, arg) { 379 accept1(ExpressionVisitor1 visitor, arg) {
(...skipping 14 matching lines...) Expand all
371 394
372 String get operator => isAnd ? '&&' : '||'; 395 String get operator => isAnd ? '&&' : '||';
373 396
374 accept(ExpressionVisitor visitor) => visitor.visitLogicalOperator(this); 397 accept(ExpressionVisitor visitor) => visitor.visitLogicalOperator(this);
375 accept1(ExpressionVisitor1 visitor, arg) { 398 accept1(ExpressionVisitor1 visitor, arg) {
376 return visitor.visitLogicalOperator(this, arg); 399 return visitor.visitLogicalOperator(this, arg);
377 } 400 }
378 } 401 }
379 402
380 /// Logical negation. 403 /// Logical negation.
404 // TODO(asgerf): Replace this class with the IsFalsy builtin operator?
405 // Right now the tree builder compiles IsFalsy to Not.
381 class Not extends Expression { 406 class Not extends Expression {
382 Expression operand; 407 Expression operand;
383 408
384 Not(this.operand); 409 Not(this.operand);
385 410
386 accept(ExpressionVisitor visitor) => visitor.visitNot(this); 411 accept(ExpressionVisitor visitor) => visitor.visitNot(this);
387 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitNot(this, arg); 412 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitNot(this, arg);
388 } 413 }
389 414
390 /// Currently unused. 415 /// Currently unused.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 E visitGetField(GetField node); 815 E visitGetField(GetField node);
791 E visitSetField(SetField node); 816 E visitSetField(SetField node);
792 E visitGetStatic(GetStatic node); 817 E visitGetStatic(GetStatic node);
793 E visitSetStatic(SetStatic node); 818 E visitSetStatic(SetStatic node);
794 E visitCreateBox(CreateBox node); 819 E visitCreateBox(CreateBox node);
795 E visitCreateInstance(CreateInstance node); 820 E visitCreateInstance(CreateInstance node);
796 E visitReifyRuntimeType(ReifyRuntimeType node); 821 E visitReifyRuntimeType(ReifyRuntimeType node);
797 E visitReadTypeVariable(ReadTypeVariable node); 822 E visitReadTypeVariable(ReadTypeVariable node);
798 E visitTypeExpression(TypeExpression node); 823 E visitTypeExpression(TypeExpression node);
799 E visitCreateInvocationMirror(CreateInvocationMirror node); 824 E visitCreateInvocationMirror(CreateInvocationMirror node);
825 E visitApplyBuiltinOperator(ApplyBuiltinOperator node);
800 } 826 }
801 827
802 abstract class ExpressionVisitor1<E, A> { 828 abstract class ExpressionVisitor1<E, A> {
803 E visitExpression(Expression node, A arg) => node.accept1(this, arg); 829 E visitExpression(Expression node, A arg) => node.accept1(this, arg);
804 E visitVariableUse(VariableUse node, A arg); 830 E visitVariableUse(VariableUse node, A arg);
805 E visitAssign(Assign node, A arg); 831 E visitAssign(Assign node, A arg);
806 E visitInvokeStatic(InvokeStatic node, A arg); 832 E visitInvokeStatic(InvokeStatic node, A arg);
807 E visitInvokeMethod(InvokeMethod node, A arg); 833 E visitInvokeMethod(InvokeMethod node, A arg);
808 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg); 834 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg);
809 E visitInvokeConstructor(InvokeConstructor node, A arg); 835 E visitInvokeConstructor(InvokeConstructor node, A arg);
(...skipping 10 matching lines...) Expand all
820 E visitGetField(GetField node, A arg); 846 E visitGetField(GetField node, A arg);
821 E visitSetField(SetField node, A arg); 847 E visitSetField(SetField node, A arg);
822 E visitGetStatic(GetStatic node, A arg); 848 E visitGetStatic(GetStatic node, A arg);
823 E visitSetStatic(SetStatic node, A arg); 849 E visitSetStatic(SetStatic node, A arg);
824 E visitCreateBox(CreateBox node, A arg); 850 E visitCreateBox(CreateBox node, A arg);
825 E visitCreateInstance(CreateInstance node, A arg); 851 E visitCreateInstance(CreateInstance node, A arg);
826 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); 852 E visitReifyRuntimeType(ReifyRuntimeType node, A arg);
827 E visitReadTypeVariable(ReadTypeVariable node, A arg); 853 E visitReadTypeVariable(ReadTypeVariable node, A arg);
828 E visitTypeExpression(TypeExpression node, A arg); 854 E visitTypeExpression(TypeExpression node, A arg);
829 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg); 855 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg);
856 E visitApplyBuiltinOperator(ApplyBuiltinOperator node, A arg);
830 } 857 }
831 858
832 abstract class StatementVisitor<S> { 859 abstract class StatementVisitor<S> {
833 S visitStatement(Statement node) => node.accept(this); 860 S visitStatement(Statement node) => node.accept(this);
834 S visitLabeledStatement(LabeledStatement node); 861 S visitLabeledStatement(LabeledStatement node);
835 S visitReturn(Return node); 862 S visitReturn(Return node);
836 S visitThrow(Throw node); 863 S visitThrow(Throw node);
837 S visitRethrow(Rethrow node); 864 S visitRethrow(Rethrow node);
838 S visitBreak(Break node); 865 S visitBreak(Break node);
839 S visitContinue(Continue node); 866 S visitContinue(Continue node);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 1045
1019 visitTypeExpression(TypeExpression node) { 1046 visitTypeExpression(TypeExpression node) {
1020 node.arguments.forEach(visitExpression); 1047 node.arguments.forEach(visitExpression);
1021 } 1048 }
1022 1049
1023 visitCreateInvocationMirror(CreateInvocationMirror node) { 1050 visitCreateInvocationMirror(CreateInvocationMirror node) {
1024 node.arguments.forEach(visitExpression); 1051 node.arguments.forEach(visitExpression);
1025 } 1052 }
1026 1053
1027 visitUnreachable(Unreachable node) {} 1054 visitUnreachable(Unreachable node) {}
1055
1056 visitApplyBuiltinOperator(ApplyBuiltinOperator node) {
1057 node.arguments.forEach(visitExpression);
1058 }
1028 } 1059 }
1029 1060
1030 abstract class Transformer implements ExpressionVisitor<Expression>, 1061 abstract class Transformer implements ExpressionVisitor<Expression>,
1031 StatementVisitor<Statement> { 1062 StatementVisitor<Statement> {
1032 Expression visitExpression(Expression e) => e.accept(this); 1063 Expression visitExpression(Expression e) => e.accept(this);
1033 Statement visitStatement(Statement s) => s.accept(this); 1064 Statement visitStatement(Statement s) => s.accept(this);
1034 } 1065 }
1035 1066
1036 class RecursiveTransformer extends Transformer { 1067 class RecursiveTransformer extends Transformer {
1037 void visitInnerFunction(FunctionDefinition node) { 1068 void visitInnerFunction(FunctionDefinition node) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } 1249 }
1219 1250
1220 visitCreateInvocationMirror(CreateInvocationMirror node) { 1251 visitCreateInvocationMirror(CreateInvocationMirror node) {
1221 _replaceExpressions(node.arguments); 1252 _replaceExpressions(node.arguments);
1222 return node; 1253 return node;
1223 } 1254 }
1224 1255
1225 visitUnreachable(Unreachable node) { 1256 visitUnreachable(Unreachable node) {
1226 return node; 1257 return node;
1227 } 1258 }
1259
1260 visitApplyBuiltinOperator(ApplyBuiltinOperator node) {
1261 _replaceExpressions(node.arguments);
1262 return node;
1263 }
1228 } 1264 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart ('k') | pkg/compiler/lib/src/tree_ir/tree_ir_tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698