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