| | |
| | | return f; |
| | | } |
| | | |
| | | newBranch(type, loc) { |
| | | newBranch(type, loc, isReportLogic = false) { |
| | | const b = this.meta.last.b; |
| | | this.data.b[b] = []; |
| | | this.data.branchMap[b] = { |
| | |
| | | line: loc && loc.start.line |
| | | }; |
| | | this.meta.last.b += 1; |
| | | this.maybeNewBranchTrue(type, b, isReportLogic); |
| | | return b; |
| | | } |
| | | |
| | | maybeNewBranchTrue(type, name, isReportLogic) { |
| | | if (!isReportLogic) { |
| | | return; |
| | | } |
| | | if (type !== 'binary-expr') { |
| | | return; |
| | | } |
| | | this.data.bT = this.data.bT || {}; |
| | | this.data.bT[name] = []; |
| | | } |
| | | |
| | | addBranchPath(name, location) { |
| | |
| | | } |
| | | bMeta.locations.push(cloneLocation(location)); |
| | | counts.push(0); |
| | | this.maybeAddBranchTrue(name); |
| | | return counts.length - 1; |
| | | } |
| | | |
| | | maybeAddBranchTrue(name) { |
| | | if (!this.data.bT) { |
| | | return; |
| | | } |
| | | const countsTrue = this.data.bT[name]; |
| | | if (!countsTrue) { |
| | | return; |
| | | } |
| | | countsTrue.push(0); |
| | | } |
| | | |
| | | /** |
| | |
| | | // prune empty branches |
| | | const map = this.data.branchMap; |
| | | const branches = this.data.b; |
| | | const branchesT = this.data.bT || {}; |
| | | Object.keys(map).forEach(b => { |
| | | if (map[b].locations.length === 0) { |
| | | delete map[b]; |
| | | delete branches[b]; |
| | | delete branchesT[b]; |
| | | } |
| | | }); |
| | | } |