Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 1x 1x 1x 105x 105x 105x 1x 109x 109x 109x 1x 1x 1x 36x 36x 3x 3x 36x 43x 35x 35x 35x 26x 26x 43x 8x 2x 2x 2x 2x 2x 43x 5x 5x 1x 1x 1x 73x 73x 3x 3x 70x 72x 70x 70x 70x | import * as Expressions from "../abap/2_statements/expressions";
import {ExpressionNode} from "../abap/nodes";
function normalize(node: ExpressionNode): string {
return node.concatTokens().toUpperCase().replace(/\s+/g, " ");
}
function hasOperator(cond: ExpressionNode, operators: string[]): boolean {
return cond.getChildren().some(c => operators.includes(c.concatTokens().toUpperCase()));
}
/** cond is true only if name is not initial: "name IS NOT INITIAL" or "lines( name ) > 0", possibly combined with AND,
* name in upper case */
export function condImpliesNotInitial(cond: ExpressionNode, name: string): boolean {
if (hasOperator(cond, ["OR", "EQUIV"])) {
return false;
}
for (const child of cond.getChildren()) {
if (child instanceof ExpressionNode && child.get() instanceof Expressions.Compare) {
if ([`${name} IS NOT INITIAL`, `NOT ${name} IS INITIAL`,
`LINES( ${name} ) > 0`, `LINES( ${name} ) GT 0`, `LINES( ${name} ) <> 0`, `LINES( ${name} ) NE 0`,
`LINES( ${name} ) >= 1`, `LINES( ${name} ) GE 1`].includes(normalize(child))) {
return true;
}
} else if (child instanceof ExpressionNode && child.get() instanceof Expressions.CondSub
&& child.getFirstToken().getStr().toUpperCase() !== "NOT") {
const sub = child.findDirectExpression(Expressions.Cond);
if (sub && condImpliesNotInitial(sub, name)) {
return true;
}
}
}
return false;
}
/** cond is false only if name is not initial: "name IS INITIAL" or "lines( name ) = 0", possibly combined with OR,
* name in upper case */
export function negationImpliesNotInitial(cond: ExpressionNode, name: string): boolean {
if (hasOperator(cond, ["AND", "EQUIV"])) {
return false;
}
return cond.getChildren().some(c => c instanceof ExpressionNode && c.get() instanceof Expressions.Compare
&& [`${name} IS INITIAL`, `NOT ${name} IS NOT INITIAL`,
`LINES( ${name} ) = 0`, `LINES( ${name} ) EQ 0`, `LINES( ${name} ) < 1`, `LINES( ${name} ) LT 1`]
.includes(normalize(c)));
}
|