All files / src/abap/5_syntax/structures constants.ts

93.1% Statements 27/29
75% Branches 15/20
100% Functions 1/1
93.1% Lines 27/29

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 461x 1x 1x 1x   1x   1x 1x   1x       11x 11x       11x 11x 11x 40x 40x 17x 17x 17x 17x   23x 1x 1x 1x 1x         11x       11x 11x    
import * as Expressions from "../../2_statements/expressions";
import * as Statements from "../../2_statements/statements";
import * as Structures from "../../3_structures/structures";
import {StructureNode, StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {TypedIdentifier, IdentifierMeta} from "../../types/_typed_identifier";
import {IStructureComponent} from "../../types/basic";
import * as Basic from "../../types/basic";
import {Constant} from "../statements/constant";
 
export class Constants {
  public runSyntax(node: StructureNode, scope: CurrentScope, filename: string):
  {type: TypedIdentifier | undefined, values: {[index: string]: string} } {
 
    const name = node.findFirstExpression(Expressions.DefinitionName)?.getFirstToken();
    Iif (name === undefined) {
      throw new Error("Constants, structure, unexpected node");
    }
 
    const components: IStructureComponent[] = [];
    const values: any = {};
    for (const c of node.getChildren()) {
      const ctyp = c.get();
      if (c instanceof StatementNode && ctyp instanceof Statements.Constant) {
        const found = new Constant().runSyntax(c, scope, filename);
        Eif (found) {
          components.push({name: found.getName(), type: found.getType()});
          values[found.getName()] = found.getValue();
        }
      } else if (c instanceof StructureNode && ctyp instanceof Structures.Constants) {
        const {type: found, values: val} = new Constants().runSyntax(c, scope, filename);
        Eif (found) {
          components.push({name: found.getName(), type: found.getType()});
          values[found.getName()] = val;
        }
      }
    }
 
    Iif (components.length === 0) {
      return {type: undefined, values};
    }
 
    const type = new TypedIdentifier(name, filename, new Basic.StructureType(components), [IdentifierMeta.ReadOnly, IdentifierMeta.Static]);
    return {type, values};
  }
}