(source: SourceFile)
| 69 | }; |
| 70 | |
| 71 | function getKernelMappingForFile(source: SourceFile) { |
| 72 | const switchStatement = getSwitchStatement(source); |
| 73 | if (switchStatement == null) { |
| 74 | throw new Error('No switch statment found in executor'); |
| 75 | } |
| 76 | const caseClauses = switchStatement.getClauses(); |
| 77 | |
| 78 | const kernelsToOp: KernelMapping = {}; |
| 79 | let currentClauseGroup: string[] = []; |
| 80 | |
| 81 | // Loop through clauses until you reach one that has a block or return. |
| 82 | // This allows us to coalesce fallthrough case blocks in a switch statement. |
| 83 | caseClauses.forEach((caseClause: CaseOrDefaultClause) => { |
| 84 | if (caseClause instanceof CaseClause) { |
| 85 | let kernelName; |
| 86 | caseClause.forEachChild(clausePart => { |
| 87 | const kind = clausePart.getKindName(); |
| 88 | if (kind === 'StringLiteral') { |
| 89 | kernelName = clausePart.getText().replace(/\'/g, ''); |
| 90 | currentClauseGroup.push(kernelName); |
| 91 | } |
| 92 | if (kind === 'Block' || kind === 'ReturnStatement') { |
| 93 | // We have reached a code block, all the previously captured |
| 94 | // kernels use this block as their execution path. |
| 95 | |
| 96 | // Parse the code block and determing all the tfc.*() function calls |
| 97 | // used. |
| 98 | const callExprs = |
| 99 | clausePart.getDescendantsOfKind(SyntaxKind.CallExpression); |
| 100 | const tfOpsCallExprs = |
| 101 | callExprs.filter(expr => expr.getText().match(/ops/)); |
| 102 | const tfSymbols: Set<string> = new Set(); |
| 103 | for (const tfOpsCall of tfOpsCallExprs) { |
| 104 | const tfOpsCallStr = tfOpsCall.getText(); |
| 105 | const functionCallMatcher = /(ops\.([\w\.]*)\()/g; |
| 106 | const matches = tfOpsCallStr.match(functionCallMatcher); |
| 107 | if (matches != null && matches.length > 0) { |
| 108 | for (const match of matches) { |
| 109 | // extract the method name (and any namespaces used to call it) |
| 110 | const symbolMatcher = /(ops\.([\w\.]*)\()/; |
| 111 | const symbol = match.match(symbolMatcher)[2]; |
| 112 | tfSymbols.add(symbol); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | for (const kern of currentClauseGroup) { |
| 117 | kernelsToOp[kern] = Array.from(tfSymbols); |
| 118 | } |
| 119 | // Reset the clause tracker as we are moving to a new set of kernels |
| 120 | currentClauseGroup = []; |
| 121 | } |
| 122 | }); |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | return kernelsToOp; |
| 127 | } |
| 128 |
no test coverage detected
searching dependent graphs…