| OLD | NEW |
| 1 library dart_backend.tracer; | 1 library dart_backend.tracer; |
| 2 | 2 |
| 3 import 'dart:async' show EventSink; | 3 import 'dart:async' show EventSink; |
| 4 import '../tracer.dart'; | 4 import '../tracer.dart'; |
| 5 import 'dart_tree.dart'; | 5 import 'dart_tree.dart'; |
| 6 | 6 |
| 7 class Block { | 7 class Block { |
| 8 int index; | 8 int index; |
| 9 final List<Statement> statements = <Statement>[]; | 9 final List<Statement> statements = <Statement>[]; |
| 10 final List<Block> predecessors = <Block>[]; | 10 final List<Block> predecessors = <Block>[]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 block.index = blocks.length; | 36 block.index = blocks.length; |
| 37 blocks.add(block); | 37 blocks.add(block); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void collect(FunctionDefinition function) { | 40 void collect(FunctionDefinition function) { |
| 41 visitStatement(function.body); | 41 visitStatement(function.body); |
| 42 } | 42 } |
| 43 | 43 |
| 44 visitVariable(Variable node) {} | 44 visitVariable(Variable node) {} |
| 45 visitInvokeStatic(InvokeStatic node) {} | 45 visitInvokeStatic(InvokeStatic node) {} |
| 46 visitInvokeMethod(InvokeMethod node) {} |
| 47 visitInvokeConstructor(InvokeConstructor node) {} |
| 46 visitConstant(Constant node) {} | 48 visitConstant(Constant node) {} |
| 47 | 49 |
| 48 visitLabeledStatement(LabeledStatement node) { | 50 visitLabeledStatement(LabeledStatement node) { |
| 49 Block target = new Block(); | 51 Block target = new Block(); |
| 50 breakTargets[node.label] = target; | 52 breakTargets[node.label] = target; |
| 51 visitStatement(node.body); | 53 visitStatement(node.body); |
| 52 _addBlock(target); | 54 _addBlock(target); |
| 53 visitStatement(node.next); | 55 visitStatement(node.next); |
| 54 } | 56 } |
| 55 | 57 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 156 |
| 155 visitLabeledStatement(LabeledStatement node) { | 157 visitLabeledStatement(LabeledStatement node) { |
| 156 // These do not get added to a block's list of statements. | 158 // These do not get added to a block's list of statements. |
| 157 } | 159 } |
| 158 | 160 |
| 159 visitAssign(Assign node) { | 161 visitAssign(Assign node) { |
| 160 String name = names.varName(node.variable); | 162 String name = names.varName(node.variable); |
| 161 String rhs = expr(node.definition); | 163 String rhs = expr(node.definition); |
| 162 printStatement(name, "let $name = $rhs"); | 164 printStatement(name, "let $name = $rhs"); |
| 163 } | 165 } |
| 166 |
| 167 visitInvokeMethod(InvokeMethod node) { |
| 168 printStatement(null, expr(node)); |
| 169 } |
| 170 |
| 171 visitInvokeConstructor(InvokeConstructor node) { |
| 172 printStatement(null, expr(node)); |
| 173 } |
| 164 | 174 |
| 165 visitReturn(Return node) { | 175 visitReturn(Return node) { |
| 166 printStatement(null, "return ${expr(node.value)}"); | 176 printStatement(null, "return ${expr(node.value)}"); |
| 167 } | 177 } |
| 168 | 178 |
| 169 visitBreak(Break node) { | 179 visitBreak(Break node) { |
| 170 printStatement(null, "break ${collector.breakTargets[node.target].name}"); | 180 printStatement(null, "break ${collector.breakTargets[node.target].name}"); |
| 171 } | 181 } |
| 172 | 182 |
| 173 visitIf(If node) { | 183 visitIf(If node) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 193 | 203 |
| 194 String visitVariable(Variable node) { | 204 String visitVariable(Variable node) { |
| 195 return names.varName(node); | 205 return names.varName(node); |
| 196 } | 206 } |
| 197 | 207 |
| 198 String visitInvokeStatic(InvokeStatic node) { | 208 String visitInvokeStatic(InvokeStatic node) { |
| 199 String head = node.target.name; | 209 String head = node.target.name; |
| 200 String args = node.arguments.map((e) => e.accept(this)).join(', '); | 210 String args = node.arguments.map((e) => e.accept(this)).join(', '); |
| 201 return "$head($args)"; | 211 return "$head($args)"; |
| 202 } | 212 } |
| 213 |
| 214 String visitInvokeMethod(InvokeMethod node) { |
| 215 String receiver = node.receiver.accept(this); |
| 216 String name = node.selector.name; |
| 217 String args = node.arguments.map((e) => e.accept(this)).join(', '); |
| 218 return "$receiver.$name($args)"; |
| 219 } |
| 220 |
| 221 String visitInvokeConstructor(InvokeConstructor node) { |
| 222 String callName; |
| 223 if (node.target.name.isEmpty) { |
| 224 callName = '${node.type}'; |
| 225 } else { |
| 226 callName = '${node.type}.${node.target.name}'; |
| 227 } |
| 228 String args = node.arguments.map(visitExpression).join(', '); |
| 229 return "new $callName($args)"; |
| 230 } |
| 203 | 231 |
| 204 String visitConstant(Constant node) { | 232 String visitConstant(Constant node) { |
| 205 return "${node.value}"; | 233 return "${node.value}"; |
| 206 } | 234 } |
| 207 | 235 |
| 208 // Note: There should not be statements in the context of expressions. | 236 // Note: There should not be statements in the context of expressions. |
| 209 String visitStatement(Statement node) { | 237 String visitStatement(Statement node) { |
| 210 return "${node.runtimeType} statement in expression context"; | 238 return "${node.runtimeType} statement in expression context"; |
| 211 } | 239 } |
| 212 | 240 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 241 } | 269 } |
| 242 while (name == null || _usedNames.contains(name)) { | 270 while (name == null || _usedNames.contains(name)) { |
| 243 name = "v${_counter++}"; | 271 name = "v${_counter++}"; |
| 244 } | 272 } |
| 245 _names[v] = name; | 273 _names[v] = name; |
| 246 _usedNames.add(name); | 274 _usedNames.add(name); |
| 247 } | 275 } |
| 248 return name; | 276 return name; |
| 249 } | 277 } |
| 250 } | 278 } |
| OLD | NEW |