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

82.45% Statements 47/57
80% Branches 12/15
100% Functions 1/1
82.45% Lines 47/57

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 571x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 47x     47x 47x 47x 5x 5x 47x 47x 47x 47x 47x 47x 41x 47x 5x 6x         47x 47x 47x 1x 47x         47x 47x 47x 47x 47x 47x 47x 47x 4x 4x 4x 4x 47x 47x 1x
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode} from "../../nodes";
import {Source} from "./source";
import {IntegerType, TableType, UnknownType, VoidType} from "../../types/basic";
import {IdentifierMeta, TypedIdentifier} from "../../types/_typed_identifier";
import {AbstractType} from "../../types/basic/_abstract_type";
import {ReferenceType} from "../_reference";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
 
export class InlineLoopDefinition {
  public static runSyntax(node: ExpressionNode | undefined, input: SyntaxInput): void {
    if (node === undefined) {
      return;
    }
 
    let target = node.findDirectExpression(Expressions.TargetField);
    if (target === undefined) {
      target = node.findDirectExpression(Expressions.TargetFieldSymbol);
    }
    const source = node.findDirectExpression(Expressions.Source);
 
    if (source && target) {
      const sourceType = Source.runSyntax(source, input);
      let rowType: AbstractType | undefined = undefined;
      if (sourceType instanceof TableType) {
        rowType = sourceType.getRowType();
      } else if (sourceType instanceof VoidType) {
        rowType = sourceType;
      } else if (sourceType instanceof UnknownType) {
        const message = "Unknown type, " + sourceType.getError();
        input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
        return;
      }
      if (rowType === undefined
          && node.concatTokens().toUpperCase().includes(" IN GROUP ")
          && sourceType !== undefined) {
        rowType = sourceType;
      } else if (rowType === undefined) {
        const message = "InlineLoopDefinition, not a table type";
        input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
        return;
      }
      const identifier = new TypedIdentifier(target.getFirstToken(), input.filename, rowType, [IdentifierMeta.InlineDefinition]);
      input.scope.addReference(target.getFirstToken(), identifier, ReferenceType.DataWriteReference, input.filename);
      input.scope.addReference(target.getFirstToken(), identifier, ReferenceType.DataReadReference, input.filename);
      input.scope.addIdentifier(identifier);
    }
 
    const index = node.findExpressionAfterToken("INTO");
    if (index && index.get() instanceof Expressions.TargetField) {
      const identifier = new TypedIdentifier(index.getFirstToken(), input.filename, IntegerType.get(), [IdentifierMeta.InlineDefinition]);
      input.scope.addReference(index.getFirstToken(), identifier, ReferenceType.DataWriteReference, input.filename);
      input.scope.addIdentifier(identifier);
    }
 
  }
}