| OLD | NEW |
| 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, GenericType; | 9 import '../dart_types.dart' show DartType, GenericType; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 /// Number of places where this variable occurs as: | 112 /// Number of places where this variable occurs as: |
| 113 /// - left-hand of an [Assign] | 113 /// - left-hand of an [Assign] |
| 114 /// - left-hand of a [FunctionDeclaration] | 114 /// - left-hand of a [FunctionDeclaration] |
| 115 /// - parameter in a [FunctionDefinition] | 115 /// - parameter in a [FunctionDefinition] |
| 116 /// - catch parameter in a [Try] | 116 /// - catch parameter in a [Try] |
| 117 int writeCount = 0; | 117 int writeCount = 0; |
| 118 | 118 |
| 119 Variable(this.host, this.element) { | 119 Variable(this.host, this.element) { |
| 120 assert(host != null); | 120 assert(host != null); |
| 121 } | 121 } |
| 122 |
| 123 String toString() => element == null ? 'Variable' : element.toString(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 /// Read the value of a variable. | 126 /// Read the value of a variable. |
| 125 class VariableUse extends Expression { | 127 class VariableUse extends Expression { |
| 126 Variable variable; | 128 Variable variable; |
| 127 | 129 |
| 128 /// Creates a use of [variable] and updates its `readCount`. | 130 /// Creates a use of [variable] and updates its `readCount`. |
| 129 VariableUse(this.variable) { | 131 VariableUse(this.variable) { |
| 130 variable.readCount++; | 132 variable.readCount++; |
| 131 } | 133 } |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 S visitStatement(Statement s) => s.accept(this); | 845 S visitStatement(Statement s) => s.accept(this); |
| 844 } | 846 } |
| 845 | 847 |
| 846 abstract class Visitor1<S, E, A> implements ExpressionVisitor1<E, A>, | 848 abstract class Visitor1<S, E, A> implements ExpressionVisitor1<E, A>, |
| 847 StatementVisitor1<S, A> { | 849 StatementVisitor1<S, A> { |
| 848 E visitExpression(Expression e, A arg) => e.accept1(this, arg); | 850 E visitExpression(Expression e, A arg) => e.accept1(this, arg); |
| 849 S visitStatement(Statement s, A arg) => s.accept1(this, arg); | 851 S visitStatement(Statement s, A arg) => s.accept1(this, arg); |
| 850 } | 852 } |
| 851 | 853 |
| 852 class RecursiveVisitor extends Visitor { | 854 class RecursiveVisitor extends Visitor { |
| 855 // TODO(asgerf): Clean up the tree visitor. |
| 856 |
| 857 visitExecutableDefinition(ExecutableDefinition node) { |
| 858 if (node is ConstructorDefinition) return visitConstructorDefinition(node); |
| 859 if (node is FunctionDefinition) return visitFunctionDefinition(node); |
| 860 if (node is FieldDefinition) return visitFieldDefinition(node); |
| 861 throw 'Unexpected ExecutableDefinition: $node'; |
| 862 } |
| 863 |
| 853 visitFunctionDefinition(FunctionDefinition node) { | 864 visitFunctionDefinition(FunctionDefinition node) { |
| 854 node.parameters.forEach(visitVariable); | 865 node.parameters.forEach(visitVariable); |
| 866 if (node.body != null) visitStatement(node.body); |
| 867 } |
| 868 |
| 869 visitConstructorDefinition(ConstructorDefinition node) { |
| 870 if (node.initializers != null) node.initializers.forEach(visitInitializer); |
| 871 visitFunctionDefinition(node); |
| 872 } |
| 873 |
| 874 visitFieldDefinition(FieldDefinition node) { |
| 875 if (node.body != null) { |
| 876 visitStatement(node.body); |
| 877 } |
| 878 } |
| 879 |
| 880 visitInitializer(Initializer node) { |
| 881 if (node is FieldInitializer) { |
| 882 return visitFieldInitializer(node); |
| 883 } else { |
| 884 return visitSuperInitializer(node); |
| 885 } |
| 886 } |
| 887 |
| 888 visitFieldInitializer(FieldInitializer node) { |
| 855 visitStatement(node.body); | 889 visitStatement(node.body); |
| 856 } | 890 } |
| 857 | 891 |
| 892 visitSuperInitializer(SuperInitializer node) { |
| 893 node.arguments.forEach(visitStatement); |
| 894 } |
| 895 |
| 858 visitVariable(Variable node) {} | 896 visitVariable(Variable node) {} |
| 859 | 897 |
| 860 visitVariableUse(VariableUse node) { | 898 visitVariableUse(VariableUse node) { |
| 861 visitVariable(node.variable); | 899 visitVariable(node.variable); |
| 862 } | 900 } |
| 863 | 901 |
| 864 visitInvokeStatic(InvokeStatic node) { | 902 visitInvokeStatic(InvokeStatic node) { |
| 865 node.arguments.forEach(visitExpression); | 903 node.arguments.forEach(visitExpression); |
| 866 } | 904 } |
| 867 | 905 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 visitExpressionStatement(ExpressionStatement node) { | 1004 visitExpressionStatement(ExpressionStatement node) { |
| 967 visitExpression(node.expression); | 1005 visitExpression(node.expression); |
| 968 visitStatement(node.next); | 1006 visitStatement(node.next); |
| 969 } | 1007 } |
| 970 | 1008 |
| 971 visitTry(Try node) { | 1009 visitTry(Try node) { |
| 972 visitStatement(node.tryBody); | 1010 visitStatement(node.tryBody); |
| 973 visitStatement(node.catchBody); | 1011 visitStatement(node.catchBody); |
| 974 } | 1012 } |
| 975 | 1013 |
| 976 visitFieldInitializer(FieldInitializer node) { | |
| 977 visitStatement(node.body); | |
| 978 } | |
| 979 | |
| 980 visitSuperInitializer(SuperInitializer node) { | |
| 981 node.arguments.forEach(visitStatement); | |
| 982 } | |
| 983 | |
| 984 visitGetField(GetField node) { | 1014 visitGetField(GetField node) { |
| 985 visitExpression(node.object); | 1015 visitExpression(node.object); |
| 986 } | 1016 } |
| 987 | 1017 |
| 988 visitSetField(SetField node) { | 1018 visitSetField(SetField node) { |
| 989 visitExpression(node.object); | 1019 visitExpression(node.object); |
| 990 visitExpression(node.value); | 1020 visitExpression(node.value); |
| 991 visitStatement(node.next); | 1021 visitStatement(node.next); |
| 992 } | 1022 } |
| 993 | 1023 |
| 994 visitCreateBox(CreateBox node) { | 1024 visitCreateBox(CreateBox node) { |
| 995 } | 1025 } |
| 996 | 1026 |
| 997 visitCreateInstance(CreateInstance node) { | 1027 visitCreateInstance(CreateInstance node) { |
| 998 node.arguments.forEach(visitExpression); | 1028 node.arguments.forEach(visitExpression); |
| 999 } | 1029 } |
| 1000 } | 1030 } |
| OLD | NEW |