| OLD | NEW |
| 1 library tree_ir.integrity; | 1 library tree_ir.integrity; |
| 2 | 2 |
| 3 import 'tree_ir_nodes.dart'; | 3 import 'tree_ir_nodes.dart'; |
| 4 | 4 |
| 5 /// Performs integrity checks on the tree_ir. | 5 /// Performs integrity checks on the tree_ir. |
| 6 /// | 6 /// |
| 7 /// Should only be run for debugging purposes, not in production. | 7 /// Should only be run for debugging purposes, not in production. |
| 8 /// | 8 /// |
| 9 /// - Reference counts on must match the actual number of references. | 9 /// - Reference counts on must match the actual number of references. |
| 10 /// - Labels must be in scope when referenced. | 10 /// - Labels must be in scope when referenced. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 if (label2declaration.containsKey(label)) { | 82 if (label2declaration.containsKey(label)) { |
| 83 error('Duplicate declaration of label $label'); | 83 error('Duplicate declaration of label $label'); |
| 84 } | 84 } |
| 85 label2declaration[label] = target; | 85 label2declaration[label] = target; |
| 86 labelUses[label] = 0; | 86 labelUses[label] = 0; |
| 87 visitStatement(target.body); | 87 visitStatement(target.body); |
| 88 label2declaration.remove(label); | 88 label2declaration.remove(label); |
| 89 | 89 |
| 90 if (labelUses[label] != label.useCount) { | 90 if (labelUses[label] != label.useCount) { |
| 91 error('Label $label has ${labelUses[label]} uses ' | 91 error('Label $label has ${labelUses[label]} uses ' |
| 92 'but its reference count is ${label.useCount}'); | 92 'but its reference count is ${label.useCount}'); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 visitLabeledStatement(LabeledStatement node) { | 96 visitLabeledStatement(LabeledStatement node) { |
| 97 visitJumpTargetBody(node); | 97 visitJumpTargetBody(node); |
| 98 visitStatement(node.next); | 98 visitStatement(node.next); |
| 99 } | 99 } |
| 100 | 100 |
| 101 visitWhileTrue(WhileTrue node) { | 101 visitWhileTrue(WhileTrue node) { |
| 102 visitJumpTargetBody(node); | 102 visitJumpTargetBody(node); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 // Verify reference counters for all variables. | 146 // Verify reference counters for all variables. |
| 147 List<Variable> seenVariables = new List<Variable>(); | 147 List<Variable> seenVariables = new List<Variable>(); |
| 148 seenVariables.addAll(varReads.keys); | 148 seenVariables.addAll(varReads.keys); |
| 149 seenVariables.addAll(varWrites.keys); | 149 seenVariables.addAll(varWrites.keys); |
| 150 for (Variable variable in seenVariables) { | 150 for (Variable variable in seenVariables) { |
| 151 int reads = varReads.putIfAbsent(variable, () => 0); | 151 int reads = varReads.putIfAbsent(variable, () => 0); |
| 152 int writes = varWrites.putIfAbsent(variable, () => 0); | 152 int writes = varWrites.putIfAbsent(variable, () => 0); |
| 153 if (reads != variable.readCount || writes != variable.writeCount) { | 153 if (reads != variable.readCount || writes != variable.writeCount) { |
| 154 error('Invalid reference count for $variable:\n' | 154 error('Invalid reference count for $variable:\n' |
| 155 '- Variable has $reads reads and $writes writes\n' | 155 '- Variable has $reads reads and $writes writes\n' |
| 156 '- Reference count is ${variable.readCount} reads and ' | 156 '- Reference count is ${variable.readCount} reads and ' |
| 157 '${variable.writeCount} writes'); | 157 '${variable.writeCount} writes'); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | |
| 162 } | 161 } |
| OLD | NEW |