All files / src/abap/5_syntax/statements perform.ts

85.29% Statements 58/68
69.23% Branches 9/13
100% Functions 1/1
85.29% Lines 58/68

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 681x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 18x     18x 18x 18x 18x 18x 2x 4x 4x 2x 18x         18x 1x 1x 1x 1x 18x 18x 18x 18x 18x     18x 18x 18x 2x 2x 2x 16x 16x 18x     16x 16x 16x 16x 18x 2x 2x 2x 2x 14x 14x 14x 14x 14x 1x
import * as Expressions from "../../2_statements/expressions";
import * as Statements from "../../2_statements/statements";
import {StatementNode} from "../../nodes";
import {ReferenceType} from "../_reference";
import {Source} from "../expressions/source";
import {StatementSyntax} from "../_statement_syntax";
import {Target} from "../expressions/target";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {AssertError} from "../assert_error";
import {Dynamic} from "../expressions/dynamic";
 
export class Perform implements StatementSyntax {
  public runSyntax(node: StatementNode, input: SyntaxInput): void {
    if (!(node.get() instanceof Statements.Perform)) {
      throw new AssertError("checkPerform unexpected node type");
    }
 
    ////////////////////////////
    // check parameters are defined
 
    for (const c of node.findDirectExpressions(Expressions.PerformChanging)) {
      for (const s of c.findDirectExpressions(Expressions.Target)) {
        new Target().runSyntax(s, input);
      }
    }
    for (const t of node.findDirectExpressions(Expressions.PerformTables)) {
      for (const s of t.findDirectExpressions(Expressions.Source)) {
        new Source().runSyntax(s, input);
      }
    }
    for (const u of node.findDirectExpressions(Expressions.PerformUsing)) {
      for (const s of u.findDirectExpressions(Expressions.Source)) {
        new Source().runSyntax(s, input);
      }
    }
 
    ////////////////////////////
    // find FORM definition
 
    if (node.findFirstExpression(Expressions.IncludeName)) {
      return; // in external program, not checked, todo
    }
 
    const dynamic = node.findFirstExpression(Expressions.Dynamic);
    if (dynamic) {
      new Dynamic().runSyntax(dynamic, input);
      return; // todo, maybe some parts can be checked
    }
 
    const expr = node.findFirstExpression(Expressions.FormName);
    if (expr === undefined) {
      return; // it might be a dynamic call
    }
 
    const name = expr.concatTokens();
 
    const found = input.scope.findFormDefinition(name);
    if (found === undefined) {
      const message = "FORM definition \"" + name + "\" not found";
      input.issues.push(syntaxIssue(input, expr.getFirstToken(), message));
      return;
    }
 
    input.scope.addReference(expr.getFirstToken(), found, ReferenceType.FormReference, input.filename);
 
    // todo, also check parameters match
  }
}