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

87.1% Statements 27/31
70% Branches 14/20
100% Functions 1/1
87.1% Lines 27/31

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 481x     1x 1x 1x   1x   1x   7x       7x 7x 3x   7x   7x 7x 7x 7x 6x 1x 1x       7x     7x 7x 7x     7x 7x 1x 1x 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 {
    Iif (node === undefined) {
      return;
    }
 
    let target = node.findDirectExpression(Expressions.TargetField);
    if (target === undefined) {
      target = node.findDirectExpression(Expressions.TargetFieldSymbol);
    }
    const source = node.findDirectExpression(Expressions.Source);
 
    Eif (source && target) {
      const sourceType = new Source().runSyntax(source, scope, filename);
      let rowType: AbstractType | undefined = undefined;
      if (sourceType instanceof TableType) {
        rowType = sourceType.getRowType();
      } else Eif (sourceType instanceof VoidType) {
        rowType = sourceType;
      } else if (sourceType instanceof UnknownType) {
        throw new Error("Unknown type, " + sourceType.getError());
      }
      Iif (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.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);
    }
 
  }
}