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

78.57% Statements 22/28
60% Branches 6/10
100% Functions 1/1
78.57% Lines 22/28

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 611x 1x     1x 1x     1x   15x             15x 2x 4x     13x         13x 1x 1x             12x       12x       12x 12x       12x   12x 12x 2x     10x        
import * as Expressions from "../../2_statements/expressions";
import * as Statements from "../../2_statements/statements";
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {ReferenceType} from "../_reference";
import {Source} from "../expressions/source";
import {StatementSyntax} from "../_statement_syntax";
 
export class Perform implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
    Iif (!(node.get() instanceof Statements.Perform)) {
      throw new Error("checkPerform unexpected node type");
    }
 
    ////////////////////////////
    // check parameters are defined
 
    for (const c of node.findDirectExpressions(Expressions.PerformChanging)) {
      for (const s of c.findDirectExpressions(Expressions.Source)) {
        new Source().runSyntax(s, scope, filename);
      }
    }
    for (const t of node.findDirectExpressions(Expressions.PerformTables)) {
      for (const s of t.findDirectExpressions(Expressions.Source)) {
        new Source().runSyntax(s, scope, filename);
      }
    }
    for (const u of node.findDirectExpressions(Expressions.PerformUsing)) {
      for (const s of u.findDirectExpressions(Expressions.Source)) {
        new Source().runSyntax(s, scope, filename);
      }
    }
 
    ////////////////////////////
    // find FORM definition
 
    Iif (node.findFirstExpression(Expressions.IncludeName)) {
      return; // in external program, not checked, todo
    }
 
    Iif (node.findFirstExpression(Expressions.Dynamic)) {
      return; // todo, maybe some parts can be checked
    }
 
    const expr = node.findFirstExpression(Expressions.FormName);
    Iif (expr === undefined) {
      return; // it might be a dynamic call
    }
 
    const name = expr.concatTokens();
 
    const found = scope.findFormDefinition(name);
    if (found === undefined) {
      throw new Error("FORM definition \"" + name + "\" not found");
    }
 
    scope.addReference(expr.getFirstToken(), found, ReferenceType.FormReference, filename);
 
    // todo, also check parameters match
  }
}