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

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

Issue 1474713002: dart2js cps: Clean up and avoid processing unreachable code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge Created 5 years 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/values.dart' as values; 7 import '../constants/values.dart' as values;
8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType;
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../io/source_information.dart' show SourceInformation; 10 import '../io/source_information.dart' show SourceInformation;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 /// [Entity] used for synthesizing a name for the variable. 108 /// [Entity] used for synthesizing a name for the variable.
109 /// Different variables may have the same entity. May be null. 109 /// Different variables may have the same entity. May be null.
110 Entity element; 110 Entity element;
111 111
112 /// Number of places where this variable occurs in a [VariableUse]. 112 /// Number of places where this variable occurs in a [VariableUse].
113 int readCount = 0; 113 int readCount = 0;
114 114
115 /// Number of places where this variable occurs as: 115 /// Number of places where this variable occurs as:
116 /// - left-hand of an [Assign] 116 /// - left-hand of an [Assign]
117 /// - left-hand of a [FunctionDeclaration]
118 /// - parameter in a [FunctionDefinition] 117 /// - parameter in a [FunctionDefinition]
119 /// - catch parameter in a [Try] 118 /// - catch parameter in a [Try]
120 int writeCount = 0; 119 int writeCount = 0;
121 120
122 /// True if an inner JS function might access this variable through a 121 /// True if an inner JS function might access this variable through a
123 /// [ForeignCode] node. 122 /// [ForeignCode] node.
124 bool isCaptured = false; 123 bool isCaptured = false;
125 124
126 Variable(this.host, this.element) { 125 Variable(this.host, this.element) {
127 assert(host != null); 126 assert(host != null);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // Right now the tree builder compiles IsFalsy to Not. 429 // Right now the tree builder compiles IsFalsy to Not.
431 class Not extends Expression { 430 class Not extends Expression {
432 Expression operand; 431 Expression operand;
433 432
434 Not(this.operand); 433 Not(this.operand);
435 434
436 accept(ExpressionVisitor visitor) => visitor.visitNot(this); 435 accept(ExpressionVisitor visitor) => visitor.visitNot(this);
437 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitNot(this, arg); 436 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitNot(this, arg);
438 } 437 }
439 438
440 /// Currently unused.
441 ///
442 /// See CreateFunction in the cps_ir_nodes.dart.
443 class FunctionExpression extends Expression {
444 final FunctionDefinition definition;
445
446 FunctionExpression(this.definition);
447
448 accept(ExpressionVisitor visitor) => visitor.visitFunctionExpression(this);
449 accept1(ExpressionVisitor1 visitor, arg) {
450 return visitor.visitFunctionExpression(this, arg);
451 }
452 }
453
454 /// A [LabeledStatement] or [WhileTrue] or [For]. 439 /// A [LabeledStatement] or [WhileTrue] or [For].
455 abstract class JumpTarget extends Statement { 440 abstract class JumpTarget extends Statement {
456 Label get label; 441 Label get label;
457 Statement get body; 442 Statement get body;
458 } 443 }
459 444
460 /** 445 /**
461 * A labeled statement. Breaks to the label within the labeled statement 446 * A labeled statement. Breaks to the label within the labeled statement
462 * target the successor statement. 447 * target the successor statement.
463 */ 448 */
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 E visitInvokeMethodDirectly(InvokeMethodDirectly node); 966 E visitInvokeMethodDirectly(InvokeMethodDirectly node);
982 E visitInvokeConstructor(InvokeConstructor node); 967 E visitInvokeConstructor(InvokeConstructor node);
983 E visitConstant(Constant node); 968 E visitConstant(Constant node);
984 E visitThis(This node); 969 E visitThis(This node);
985 E visitConditional(Conditional node); 970 E visitConditional(Conditional node);
986 E visitLogicalOperator(LogicalOperator node); 971 E visitLogicalOperator(LogicalOperator node);
987 E visitNot(Not node); 972 E visitNot(Not node);
988 E visitLiteralList(LiteralList node); 973 E visitLiteralList(LiteralList node);
989 E visitLiteralMap(LiteralMap node); 974 E visitLiteralMap(LiteralMap node);
990 E visitTypeOperator(TypeOperator node); 975 E visitTypeOperator(TypeOperator node);
991 E visitFunctionExpression(FunctionExpression node);
992 E visitGetField(GetField node); 976 E visitGetField(GetField node);
993 E visitSetField(SetField node); 977 E visitSetField(SetField node);
994 E visitGetStatic(GetStatic node); 978 E visitGetStatic(GetStatic node);
995 E visitSetStatic(SetStatic node); 979 E visitSetStatic(SetStatic node);
996 E visitGetTypeTestProperty(GetTypeTestProperty node); 980 E visitGetTypeTestProperty(GetTypeTestProperty node);
997 E visitCreateBox(CreateBox node); 981 E visitCreateBox(CreateBox node);
998 E visitCreateInstance(CreateInstance node); 982 E visitCreateInstance(CreateInstance node);
999 E visitReifyRuntimeType(ReifyRuntimeType node); 983 E visitReifyRuntimeType(ReifyRuntimeType node);
1000 E visitReadTypeVariable(ReadTypeVariable node); 984 E visitReadTypeVariable(ReadTypeVariable node);
1001 E visitTypeExpression(TypeExpression node); 985 E visitTypeExpression(TypeExpression node);
(...skipping 17 matching lines...) Expand all
1019 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg); 1003 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg);
1020 E visitInvokeConstructor(InvokeConstructor node, A arg); 1004 E visitInvokeConstructor(InvokeConstructor node, A arg);
1021 E visitConstant(Constant node, A arg); 1005 E visitConstant(Constant node, A arg);
1022 E visitThis(This node, A arg); 1006 E visitThis(This node, A arg);
1023 E visitConditional(Conditional node, A arg); 1007 E visitConditional(Conditional node, A arg);
1024 E visitLogicalOperator(LogicalOperator node, A arg); 1008 E visitLogicalOperator(LogicalOperator node, A arg);
1025 E visitNot(Not node, A arg); 1009 E visitNot(Not node, A arg);
1026 E visitLiteralList(LiteralList node, A arg); 1010 E visitLiteralList(LiteralList node, A arg);
1027 E visitLiteralMap(LiteralMap node, A arg); 1011 E visitLiteralMap(LiteralMap node, A arg);
1028 E visitTypeOperator(TypeOperator node, A arg); 1012 E visitTypeOperator(TypeOperator node, A arg);
1029 E visitFunctionExpression(FunctionExpression node, A arg);
1030 E visitGetField(GetField node, A arg); 1013 E visitGetField(GetField node, A arg);
1031 E visitSetField(SetField node, A arg); 1014 E visitSetField(SetField node, A arg);
1032 E visitGetStatic(GetStatic node, A arg); 1015 E visitGetStatic(GetStatic node, A arg);
1033 E visitSetStatic(SetStatic node, A arg); 1016 E visitSetStatic(SetStatic node, A arg);
1034 E visitGetTypeTestProperty(GetTypeTestProperty node, A arg); 1017 E visitGetTypeTestProperty(GetTypeTestProperty node, A arg);
1035 E visitCreateBox(CreateBox node, A arg); 1018 E visitCreateBox(CreateBox node, A arg);
1036 E visitCreateInstance(CreateInstance node, A arg); 1019 E visitCreateInstance(CreateInstance node, A arg);
1037 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); 1020 E visitReifyRuntimeType(ReifyRuntimeType node, A arg);
1038 E visitReadTypeVariable(ReadTypeVariable node, A arg); 1021 E visitReadTypeVariable(ReadTypeVariable node, A arg);
1039 E visitTypeExpression(TypeExpression node, A arg); 1022 E visitTypeExpression(TypeExpression node, A arg);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 S visitTry(Try node, A arg); 1064 S visitTry(Try node, A arg);
1082 S visitUnreachable(Unreachable node, A arg); 1065 S visitUnreachable(Unreachable node, A arg);
1083 S visitForeignStatement(ForeignStatement node, A arg); 1066 S visitForeignStatement(ForeignStatement node, A arg);
1084 S visitYield(Yield node, A arg); 1067 S visitYield(Yield node, A arg);
1085 } 1068 }
1086 1069
1087 abstract class RecursiveVisitor implements StatementVisitor, ExpressionVisitor { 1070 abstract class RecursiveVisitor implements StatementVisitor, ExpressionVisitor {
1088 visitExpression(Expression e) => e.accept(this); 1071 visitExpression(Expression e) => e.accept(this);
1089 visitStatement(Statement s) => s.accept(this); 1072 visitStatement(Statement s) => s.accept(this);
1090 1073
1091 visitInnerFunction(FunctionDefinition node);
1092
1093 visitVariable(Variable variable) {} 1074 visitVariable(Variable variable) {}
1094 1075
1095 visitVariableUse(VariableUse node) { 1076 visitVariableUse(VariableUse node) {
1096 visitVariable(node.variable); 1077 visitVariable(node.variable);
1097 } 1078 }
1098 1079
1099 visitAssign(Assign node) { 1080 visitAssign(Assign node) {
1100 visitVariable(node.variable); 1081 visitVariable(node.variable);
1101 visitExpression(node.value); 1082 visitExpression(node.value);
1102 } 1083 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 visitExpression(entry.key); 1128 visitExpression(entry.key);
1148 visitExpression(entry.value); 1129 visitExpression(entry.value);
1149 }); 1130 });
1150 } 1131 }
1151 1132
1152 visitTypeOperator(TypeOperator node) { 1133 visitTypeOperator(TypeOperator node) {
1153 visitExpression(node.value); 1134 visitExpression(node.value);
1154 node.typeArguments.forEach(visitExpression); 1135 node.typeArguments.forEach(visitExpression);
1155 } 1136 }
1156 1137
1157 visitFunctionExpression(FunctionExpression node) {
1158 visitInnerFunction(node.definition);
1159 }
1160
1161 visitLabeledStatement(LabeledStatement node) { 1138 visitLabeledStatement(LabeledStatement node) {
1162 visitStatement(node.body); 1139 visitStatement(node.body);
1163 visitStatement(node.next); 1140 visitStatement(node.next);
1164 } 1141 }
1165 1142
1166 visitReturn(Return node) { 1143 visitReturn(Return node) {
1167 visitExpression(node.value); 1144 visitExpression(node.value);
1168 } 1145 }
1169 1146
1170 visitThrow(Throw node) { 1147 visitThrow(Throw node) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 } 1279 }
1303 } 1280 }
1304 1281
1305 abstract class Transformer implements ExpressionVisitor<Expression>, 1282 abstract class Transformer implements ExpressionVisitor<Expression>,
1306 StatementVisitor<Statement> { 1283 StatementVisitor<Statement> {
1307 Expression visitExpression(Expression e) => e.accept(this); 1284 Expression visitExpression(Expression e) => e.accept(this);
1308 Statement visitStatement(Statement s) => s.accept(this); 1285 Statement visitStatement(Statement s) => s.accept(this);
1309 } 1286 }
1310 1287
1311 class RecursiveTransformer extends Transformer { 1288 class RecursiveTransformer extends Transformer {
1312 void visitInnerFunction(FunctionDefinition node) {
1313 node.body = visitStatement(node.body);
1314 }
1315
1316 void _replaceExpressions(List<Expression> list) { 1289 void _replaceExpressions(List<Expression> list) {
1317 for (int i = 0; i < list.length; i++) { 1290 for (int i = 0; i < list.length; i++) {
1318 list[i] = visitExpression(list[i]); 1291 list[i] = visitExpression(list[i]);
1319 } 1292 }
1320 } 1293 }
1321 1294
1322 visitVariableUse(VariableUse node) => node; 1295 visitVariableUse(VariableUse node) => node;
1323 1296
1324 visitAssign(Assign node) { 1297 visitAssign(Assign node) {
1325 node.value = visitExpression(node.value); 1298 node.value = visitExpression(node.value);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 }); 1355 });
1383 return node; 1356 return node;
1384 } 1357 }
1385 1358
1386 visitTypeOperator(TypeOperator node) { 1359 visitTypeOperator(TypeOperator node) {
1387 node.value = visitExpression(node.value); 1360 node.value = visitExpression(node.value);
1388 _replaceExpressions(node.typeArguments); 1361 _replaceExpressions(node.typeArguments);
1389 return node; 1362 return node;
1390 } 1363 }
1391 1364
1392 visitFunctionExpression(FunctionExpression node) {
1393 visitInnerFunction(node.definition);
1394 return node;
1395 }
1396
1397 visitLabeledStatement(LabeledStatement node) { 1365 visitLabeledStatement(LabeledStatement node) {
1398 node.body = visitStatement(node.body); 1366 node.body = visitStatement(node.body);
1399 node.next = visitStatement(node.next); 1367 node.next = visitStatement(node.next);
1400 return node; 1368 return node;
1401 } 1369 }
1402 1370
1403 visitReturn(Return node) { 1371 visitReturn(Return node) {
1404 node.value = visitExpression(node.value); 1372 node.value = visitExpression(node.value);
1405 return node; 1373 return node;
1406 } 1374 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 1564
1597 /// Number of uses of the current fallthrough target. 1565 /// Number of uses of the current fallthrough target.
1598 int get useCount => _stack.last.useCount; 1566 int get useCount => _stack.last.useCount;
1599 1567
1600 /// Indicate that a statement will fall through to the current fallthrough 1568 /// Indicate that a statement will fall through to the current fallthrough
1601 /// target. 1569 /// target.
1602 void use() { 1570 void use() {
1603 ++_stack.last.useCount; 1571 ++_stack.last.useCount;
1604 } 1572 }
1605 } 1573 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/tree_ir/tree_ir_integrity.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