All files / src/abap/5_syntax/expressions for.ts

100% Statements 65/65
100% Branches 20/20
100% Functions 1/1
100% Lines 65/65

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 651x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 48x 48x 79x 80x 25x 25x 79x 80x 7x 7x 7x 7x 7x 79x 80x 14x 14x 79x 80x 3x 3x 79x 80x 25x 25x 79x 80x 4x 4x 79x 79x 79x 1x
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode, StatementNode} from "../../nodes";
import {InlineFieldDefinition} from "./inline_field_definition";
import {Source} from "./source";
import {InlineLoopDefinition} from "./inline_loop_definition";
import {ScopeType} from "../_scope_type";
import {ComponentCond} from "./component_cond";
import {Cond} from "./cond";
import {VoidType} from "../../types/basic";
import {IdentifierMeta, TypedIdentifier} from "../../types/_typed_identifier";
import {ReferenceType} from "../_reference";
import {Let} from "./let";
import {SyntaxInput} from "../_syntax_input";
 
export class For {
  public static runSyntax(node: ExpressionNode | StatementNode, input: SyntaxInput): boolean {
    let scoped = false;
    const inlineLoop = node.findDirectExpressions(Expressions.InlineLoopDefinition);
    const inlineField = node.findDirectExpressions(Expressions.InlineFieldDefinition);
    const groupsToken = node.findExpressionAfterToken("GROUPS")?.getFirstToken();
    const lett = node.findDirectExpression(Expressions.Let);
    const addScope = inlineLoop.length > 0
      || inlineField.length > 0
      || lett !== undefined
      || groupsToken !== undefined;
    if (addScope) {
      // this scope is popped in parent expressions
      input.scope.push(ScopeType.For, "FOR", node.getFirstToken().getStart(), input.filename);
      scoped = true;
    }
 
    for (const s of inlineLoop) {
      InlineLoopDefinition.runSyntax(s, input);
    }
 
    for (const f of inlineField) {
      InlineFieldDefinition.runSyntax(f, input);
    }
 
    if (groupsToken !== undefined) {
      const type = VoidType.get("todoGroupBy");
      const identifier = new TypedIdentifier(groupsToken, input.filename, type, [IdentifierMeta.InlineDefinition]);
      input.scope.addIdentifier(identifier);
      input.scope.addReference(groupsToken, identifier, ReferenceType.DataWriteReference, input.filename);
    }
 
    for (const s of node.findDirectExpressions(Expressions.Source)) {
      Source.runSyntax(s, input);
    }
 
    for (const s of node.findDirectExpressions(Expressions.ComponentCond)) {
      ComponentCond.runSyntax(s, input);
    }
 
    for (const s of node.findDirectExpressions(Expressions.Cond)) {
      Cond.runSyntax(s, input);
    }
 
    if (lett) {
      Let.runSyntax(lett, input, true);
    }
 
    return scoped;
  }
}