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

87.76% Statements 43/49
66.67% Branches 6/9
100% Functions 1/1
87.76% Lines 43/49

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 491x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x     8x 8x 8x 3x 3x 8x 8x 8x 8x 8x 8x 7x 8x 1x 1x     8x     8x 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 1x 8x 8x 1x
import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
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";
 
export class InlineLoopDefinition {
  public runSyntax(node: ExpressionNode | undefined, scope: CurrentScope, filename: string): 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 = new Source().runSyntax(source, scope, filename);
      let rowType: AbstractType | undefined = undefined;
      if (sourceType instanceof TableType) {
        rowType = sourceType.getRowType();
      } else if (sourceType instanceof VoidType) {
        rowType = sourceType;
      } else if (sourceType instanceof UnknownType) {
        throw new Error("Unknown type, " + sourceType.getError());
      }
      if (rowType === undefined) {
        throw new Error("InlineLoopDefinition, not a table type");
      }
      const identifier = new TypedIdentifier(target.getFirstToken(), filename, rowType, [IdentifierMeta.InlineDefinition]);
      scope.addReference(target.getFirstToken(), identifier, ReferenceType.DataWriteReference, filename);
      scope.addReference(target.getFirstToken(), identifier, ReferenceType.DataReadReference, filename);
      scope.addIdentifier(identifier);
    }
 
    const index = node.findExpressionAfterToken("INTO");
    if (index && index.get() instanceof Expressions.TargetField) {
      const identifier = new TypedIdentifier(index.getFirstToken(), filename, new IntegerType(), [IdentifierMeta.InlineDefinition]);
      scope.addReference(index.getFirstToken(), identifier, ReferenceType.DataWriteReference, filename);
      scope.addIdentifier(identifier);
    }
 
  }
}