| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'package:kernel/ast.dart'; | 5 import 'package:kernel/ast.dart'; |
| 6 | 6 |
| 7 /// Base class for [TypeInferenceListener] that defines the API for debugging. | 7 /// Base class for [TypeInferenceListener] that defines the API for debugging. |
| 8 /// | 8 /// |
| 9 /// By default no debug info is printed. To enable debug printing, mix in | 9 /// By default no debug info is printed. To enable debug printing, mix in |
| 10 /// [TypeInferenceDebugging]. | 10 /// [TypeInferenceDebugging]. |
| 11 class TypeInferenceBase { | 11 class TypeInferenceBase { |
| 12 bool debugExpressionEnter( | 12 bool debugExpressionEnter( |
| 13 String expressionType, Expression expression, DartType typeContext) { | 13 String expressionType, Expression expression, DartType typeContext) { |
| 14 return false; | 14 return false; |
| 15 } | 15 } |
| 16 | 16 |
| 17 debugExpressionExit( | 17 void debugExpressionExit( |
| 18 String expressionType, Expression expression, DartType inferredType) {} | 18 String expressionType, Expression expression, DartType inferredType) {} |
| 19 |
| 20 void debugStatementEnter(String statementType, Statement statement) {} |
| 21 |
| 22 void debugStatementExit(String statementType, Statement statement) {} |
| 19 } | 23 } |
| 20 | 24 |
| 21 /// Mixin which can be applied to [TypeInferenceListener] to cause debug info to | 25 /// Mixin which can be applied to [TypeInferenceListener] to cause debug info to |
| 22 /// be printed. | 26 /// be printed. |
| 23 class TypeInferenceDebugging implements TypeInferenceBase { | 27 class TypeInferenceDebugging implements TypeInferenceBase { |
| 24 bool debugExpressionEnter( | 28 bool debugExpressionEnter( |
| 25 String expressionType, Expression expression, DartType typeContext) { | 29 String expressionType, Expression expression, DartType typeContext) { |
| 26 print('Enter $expressionType($expression) (context=$typeContext)'); | 30 print('Enter $expressionType($expression) (context=$typeContext)'); |
| 27 return true; | 31 return true; |
| 28 } | 32 } |
| 29 | 33 |
| 30 debugExpressionExit( | 34 void debugExpressionExit( |
| 31 String expressionType, Expression expression, DartType inferredType) { | 35 String expressionType, Expression expression, DartType inferredType) { |
| 32 print('Exit $expressionType($expression) (type=$inferredType)'); | 36 print('Exit $expressionType($expression) (type=$inferredType)'); |
| 33 } | 37 } |
| 38 |
| 39 void debugStatementEnter(String statementType, Statement statement) { |
| 40 print('Enter $statementType($statement)'); |
| 41 } |
| 42 |
| 43 void debugStatementExit(String statementType, Statement statement) { |
| 44 print('Exit $statementType($statement)'); |
| 45 } |
| 34 } | 46 } |
| 35 | 47 |
| 36 /// Callback interface used by [TypeInferrer] to report the results of type | 48 /// Callback interface used by [TypeInferrer] to report the results of type |
| 37 /// inference to a client. | 49 /// inference to a client. |
| 38 /// | 50 /// |
| 39 /// The interface is structured as a set of enter/exit methods. The enter | 51 /// The interface is structured as a set of enter/exit methods. The enter |
| 40 /// methods are called as the inferrer recurses down through the AST, and the | 52 /// methods are called as the inferrer recurses down through the AST, and the |
| 41 /// exit methods are called on the way back up. The enter methods take a | 53 /// exit methods are called on the way back up. The enter methods take a |
| 42 /// [DartType] argument representing the downwards inference context, and return | 54 /// [DartType] argument representing the downwards inference context, and return |
| 43 /// a bool indicating whether the TypeInferenceListener needs to know the final | 55 /// a bool indicating whether the TypeInferenceListener needs to know the final |
| 44 /// inferred type; the exit methods take [DartType] argument representing the | 56 /// inferred type; the exit methods take [DartType] argument representing the |
| 45 /// final inferred type. | 57 /// final inferred type. |
| 46 /// | 58 /// |
| 47 /// The default implementation (in this base class) does nothing, however it can | 59 /// The default implementation (in this base class) does nothing, however it can |
| 48 /// be used to debug type inference by uncommenting the | 60 /// be used to debug type inference by uncommenting the |
| 49 /// "with TypeInferenceDebugging" clause below. | 61 /// "with TypeInferenceDebugging" clause below. |
| 50 class TypeInferenceListener | 62 class TypeInferenceListener |
| 51 extends TypeInferenceBase // with TypeInferenceDebugging | 63 extends TypeInferenceBase // with TypeInferenceDebugging |
| 52 { | 64 { |
| 53 bool asExpressionEnter(AsExpression expression, DartType typeContext) => | 65 bool asExpressionEnter(AsExpression expression, DartType typeContext) => |
| 54 debugExpressionEnter("asExpression", expression, typeContext); | 66 debugExpressionEnter("asExpression", expression, typeContext); |
| 55 | 67 |
| 56 void asExpressionExit(AsExpression expression, DartType inferredType) => | 68 void asExpressionExit(AsExpression expression, DartType inferredType) => |
| 57 debugExpressionExit("asExpression", expression, inferredType); | 69 debugExpressionExit("asExpression", expression, inferredType); |
| 58 | 70 |
| 71 void blockEnter(Block statement) => debugStatementEnter('block', statement); |
| 72 |
| 73 void blockExit(Block statement) => debugStatementExit('block', statement); |
| 74 |
| 59 bool boolLiteralEnter(BoolLiteral expression, DartType typeContext) => | 75 bool boolLiteralEnter(BoolLiteral expression, DartType typeContext) => |
| 60 debugExpressionEnter("boolLiteral", expression, typeContext); | 76 debugExpressionEnter("boolLiteral", expression, typeContext); |
| 61 | 77 |
| 62 void boolLiteralExit(BoolLiteral expression, DartType inferredType) => | 78 void boolLiteralExit(BoolLiteral expression, DartType inferredType) => |
| 63 debugExpressionExit("boolLiteral", expression, inferredType); | 79 debugExpressionExit("boolLiteral", expression, inferredType); |
| 64 | 80 |
| 65 bool conditionalExpressionEnter( | 81 bool conditionalExpressionEnter( |
| 66 ConditionalExpression expression, DartType typeContext) => | 82 ConditionalExpression expression, DartType typeContext) => |
| 67 debugExpressionEnter("conditionalExpression", expression, typeContext); | 83 debugExpressionEnter("conditionalExpression", expression, typeContext); |
| 68 | 84 |
| 69 void conditionalExpressionExit( | 85 void conditionalExpressionExit( |
| 70 ConditionalExpression expression, DartType inferredType) => | 86 ConditionalExpression expression, DartType inferredType) => |
| 71 debugExpressionExit("conditionalExpression", expression, inferredType); | 87 debugExpressionExit("conditionalExpression", expression, inferredType); |
| 72 | 88 |
| 73 bool constructorInvocationEnter( | 89 bool constructorInvocationEnter( |
| 74 ConstructorInvocation expression, DartType typeContext) => | 90 ConstructorInvocation expression, DartType typeContext) => |
| 75 debugExpressionEnter("constructorInvocation", expression, typeContext); | 91 debugExpressionEnter("constructorInvocation", expression, typeContext); |
| 76 | 92 |
| 77 void constructorInvocationExit( | 93 void constructorInvocationExit( |
| 78 ConstructorInvocation expression, DartType inferredType) => | 94 ConstructorInvocation expression, DartType inferredType) => |
| 79 debugExpressionExit("constructorInvocation", expression, inferredType); | 95 debugExpressionExit("constructorInvocation", expression, inferredType); |
| 80 | 96 |
| 81 bool doubleLiteralEnter(DoubleLiteral expression, DartType typeContext) => | 97 bool doubleLiteralEnter(DoubleLiteral expression, DartType typeContext) => |
| 82 debugExpressionEnter("doubleLiteral", expression, typeContext); | 98 debugExpressionEnter("doubleLiteral", expression, typeContext); |
| 83 | 99 |
| 84 void doubleLiteralExit(DoubleLiteral expression, DartType inferredType) => | 100 void doubleLiteralExit(DoubleLiteral expression, DartType inferredType) => |
| 85 debugExpressionExit("doubleLiteral", expression, inferredType); | 101 debugExpressionExit("doubleLiteral", expression, inferredType); |
| 86 | 102 |
| 103 void expressionStatementEnter(ExpressionStatement statement) => |
| 104 debugStatementEnter('expressionStatement', statement); |
| 105 |
| 106 void expressionStatementExit(ExpressionStatement statement) => |
| 107 debugStatementExit('expressionStatement', statement); |
| 108 |
| 109 void functionDeclarationEnter(FunctionDeclaration statement) => |
| 110 debugStatementEnter('functionDeclaration', statement); |
| 111 |
| 112 void functionDeclarationExit(FunctionDeclaration statement) => |
| 113 debugStatementExit('functionDeclaration', statement); |
| 114 |
| 87 bool functionExpressionEnter( | 115 bool functionExpressionEnter( |
| 88 FunctionExpression expression, DartType typeContext) => | 116 FunctionExpression expression, DartType typeContext) => |
| 89 debugExpressionEnter("functionExpression", expression, typeContext); | 117 debugExpressionEnter("functionExpression", expression, typeContext); |
| 90 | 118 |
| 91 void functionExpressionExit( | 119 void functionExpressionExit( |
| 92 FunctionExpression expression, DartType inferredType) => | 120 FunctionExpression expression, DartType inferredType) => |
| 93 debugExpressionExit("functionExpression", expression, inferredType); | 121 debugExpressionExit("functionExpression", expression, inferredType); |
| 94 | 122 |
| 123 void ifStatementEnter(IfStatement statement) => |
| 124 debugStatementEnter('ifStatement', statement); |
| 125 |
| 126 void ifStatementExit(IfStatement statement) => |
| 127 debugStatementExit('ifStatement', statement); |
| 128 |
| 95 bool intLiteralEnter(IntLiteral expression, DartType typeContext) => | 129 bool intLiteralEnter(IntLiteral expression, DartType typeContext) => |
| 96 debugExpressionEnter("intLiteral", expression, typeContext); | 130 debugExpressionEnter("intLiteral", expression, typeContext); |
| 97 | 131 |
| 98 void intLiteralExit(IntLiteral expression, DartType inferredType) => | 132 void intLiteralExit(IntLiteral expression, DartType inferredType) => |
| 99 debugExpressionExit("intLiteral", expression, inferredType); | 133 debugExpressionExit("intLiteral", expression, inferredType); |
| 100 | 134 |
| 101 bool isExpressionEnter(IsExpression expression, DartType typeContext) => | 135 bool isExpressionEnter(IsExpression expression, DartType typeContext) => |
| 102 debugExpressionEnter("isExpression", expression, typeContext); | 136 debugExpressionEnter("isExpression", expression, typeContext); |
| 103 | 137 |
| 104 void isExpressionExit(IsExpression expression, DartType inferredType) => | 138 void isExpressionExit(IsExpression expression, DartType inferredType) => |
| (...skipping 18 matching lines...) Expand all Loading... |
| 123 void methodInvocationExit( | 157 void methodInvocationExit( |
| 124 MethodInvocation expression, DartType inferredType) => | 158 MethodInvocation expression, DartType inferredType) => |
| 125 debugExpressionExit("methodInvocation", expression, inferredType); | 159 debugExpressionExit("methodInvocation", expression, inferredType); |
| 126 | 160 |
| 127 bool nullLiteralEnter(NullLiteral expression, DartType typeContext) => | 161 bool nullLiteralEnter(NullLiteral expression, DartType typeContext) => |
| 128 debugExpressionEnter("nullLiteral", expression, typeContext); | 162 debugExpressionEnter("nullLiteral", expression, typeContext); |
| 129 | 163 |
| 130 void nullLiteralExit(NullLiteral expression, DartType inferredType) => | 164 void nullLiteralExit(NullLiteral expression, DartType inferredType) => |
| 131 debugExpressionExit("nullLiteral", expression, inferredType); | 165 debugExpressionExit("nullLiteral", expression, inferredType); |
| 132 | 166 |
| 167 void returnStatementEnter(ReturnStatement statement) => |
| 168 debugStatementEnter('returnStatement', statement); |
| 169 |
| 170 void returnStatementExit(ReturnStatement statement) => |
| 171 debugStatementExit('returnStatement', statement); |
| 172 |
| 133 bool staticGetEnter(StaticGet expression, DartType typeContext) => | 173 bool staticGetEnter(StaticGet expression, DartType typeContext) => |
| 134 debugExpressionEnter("staticGet", expression, typeContext); | 174 debugExpressionEnter("staticGet", expression, typeContext); |
| 135 | 175 |
| 136 void staticGetExit(StaticGet expression, DartType inferredType) => | 176 void staticGetExit(StaticGet expression, DartType inferredType) => |
| 137 debugExpressionExit("staticGet", expression, inferredType); | 177 debugExpressionExit("staticGet", expression, inferredType); |
| 138 | 178 |
| 139 bool staticInvocationEnter( | 179 bool staticInvocationEnter( |
| 140 StaticInvocation expression, DartType typeContext) => | 180 StaticInvocation expression, DartType typeContext) => |
| 141 debugExpressionEnter("staticInvocation", expression, typeContext); | 181 debugExpressionEnter("staticInvocation", expression, typeContext); |
| 142 | 182 |
| 143 void staticInvocationExit( | 183 void staticInvocationExit( |
| 144 StaticInvocation expression, DartType inferredType) => | 184 StaticInvocation expression, DartType inferredType) => |
| 145 debugExpressionExit("staticInvocation", expression, inferredType); | 185 debugExpressionExit("staticInvocation", expression, inferredType); |
| 146 | 186 |
| 147 bool stringConcatenationEnter( | 187 bool stringConcatenationEnter( |
| 148 StringConcatenation expression, DartType typeContext) => | 188 StringConcatenation expression, DartType typeContext) => |
| 149 debugExpressionEnter("stringConcatenation", expression, typeContext); | 189 debugExpressionEnter("stringConcatenation", expression, typeContext); |
| 150 | 190 |
| 151 void stringConcatenationExit( | 191 void stringConcatenationExit( |
| 152 StringConcatenation expression, DartType inferredType) => | 192 StringConcatenation expression, DartType inferredType) => |
| 153 debugExpressionExit("stringConcatenation", expression, inferredType); | 193 debugExpressionExit("stringConcatenation", expression, inferredType); |
| 154 | 194 |
| 155 bool stringLiteralEnter(StringLiteral expression, DartType typeContext) => | 195 bool stringLiteralEnter(StringLiteral expression, DartType typeContext) => |
| 156 debugExpressionEnter("StringLiteral", expression, typeContext); | 196 debugExpressionEnter("StringLiteral", expression, typeContext); |
| 157 | 197 |
| 158 void stringLiteralExit(StringLiteral expression, DartType inferredType) => | 198 void stringLiteralExit(StringLiteral expression, DartType inferredType) => |
| 159 debugExpressionExit("StringLiteral", expression, inferredType); | 199 debugExpressionExit("StringLiteral", expression, inferredType); |
| 160 | 200 |
| 201 void variableDeclarationEnter(VariableDeclaration statement) => |
| 202 debugStatementEnter('variableDeclaration', statement); |
| 203 |
| 204 void variableDeclarationExit(VariableDeclaration statement) => |
| 205 debugStatementExit('variableDeclaration', statement); |
| 206 |
| 161 bool variableGetEnter(VariableGet expression, DartType typeContext) => | 207 bool variableGetEnter(VariableGet expression, DartType typeContext) => |
| 162 debugExpressionEnter("variableGet", expression, typeContext); | 208 debugExpressionEnter("variableGet", expression, typeContext); |
| 163 | 209 |
| 164 void variableGetExit(VariableGet expression, DartType inferredType) => | 210 void variableGetExit(VariableGet expression, DartType inferredType) => |
| 165 debugExpressionExit("variableGet", expression, inferredType); | 211 debugExpressionExit("variableGet", expression, inferredType); |
| 166 | 212 |
| 167 bool variableSetEnter(VariableSet expression, DartType typeContext) => | 213 bool variableSetEnter(VariableSet expression, DartType typeContext) => |
| 168 debugExpressionEnter("variableSet", expression, typeContext); | 214 debugExpressionEnter("variableSet", expression, typeContext); |
| 169 | 215 |
| 170 void variableSetExit(VariableSet expression, DartType inferredType) => | 216 void variableSetExit(VariableSet expression, DartType inferredType) => |
| 171 debugExpressionExit("variableSet", expression, inferredType); | 217 debugExpressionExit("variableSet", expression, inferredType); |
| 172 } | 218 } |
| OLD | NEW |