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

80.48% Statements 33/41
76.92% Branches 10/13
100% Functions 1/1
80.48% Lines 33/41

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 411x 1x 1x 1x 1x 1x 1x 1x 1x 1x 970x 970x 142x 142x 828x 828x 828x 828x 828x 1x 1x 827x 828x 6x 6x 6x 6x 6x 6x 821x 821x 821x                 1x
import {CurrentScope} from "../_current_scope";
import {StatementNode} from "../../nodes";
import {BasicTypes} from "../basic_types";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {PackedType, UnknownType} from "../../types/basic";
import * as Expressions from "../../2_statements/expressions";
import {TypeTable} from "../expressions/type_table";
 
export class Type {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string, qualifiedNamePrefix?: string): TypedIdentifier | undefined {
    const tt = node.findFirstExpression(Expressions.TypeTable);
    if (tt) {
      return new TypeTable().runSyntax(node, scope, filename, qualifiedNamePrefix);
    }
 
    const found = new BasicTypes(filename, scope).simpleType(node, qualifiedNamePrefix);
    if (found) {
      if (found?.getType().isGeneric() === true
          && found?.getType().containsVoid() === false) {
        throw new Error("TYPES definition cannot be generic, " + found.getName());
      }
 
      if (scope.isGlobalOO() && found.getType() instanceof PackedType) {
        const concat = node.concatTokens().toUpperCase();
        if ((concat.includes(" TYPE P ") || concat.includes(" TYPE P."))
            && concat.includes(" DECIMALS ") === false) {
          throw new Error("Specify DECIMALS in OO context for packed");
        }
      }
 
      return found;
    }

    const fallback = node.findFirstExpression(Expressions.NamespaceSimpleName);
    if (fallback) {
      return new TypedIdentifier(fallback.getFirstToken(), filename, new UnknownType("Type, fallback"));
    }

    return undefined;
  }
}