All files / src/codegen mainContractGen.ts

100% Statements 40/40
100% Branches 0/0
100% Functions 5/5
100% Lines 39/39

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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78    1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 85x       17x                                                 17x 17x 340x   17x       340x      
import { ContractSchema } from "./contractSchema";
import { Generator } from "./generator";
import { ConstructorGen } from "./generators/constructorGen";
import { ContractEndGen } from "./generators/contractEndGen";
import { ContractStartGen } from "./generators/contractStartGen";
import { DynamicRefFuncGen } from "./generators/dynamicRefFuncGen";
import { FieldFuncGen } from "./generators/fieldFuncGen";
import { GeneralFuncGen } from "./generators/generalFuncGen";
import { HeaderGen } from "./generators/headerGen";
import { MemberVarsGen } from "./generators/memberVars";
import { MetadataStructGen } from "./generators/metadataStructGen";
import { MintFuncGen } from "./generators/mintFuncGen";
import { OverrideFuncGen } from "./generators/overrideFuncGen";
import { PackFuncGen } from "./generators/packFuncGen";
import { PatchFuncGen } from "./generators/patchFuncGen";
import { SchemaFuncGen } from "./generators/schemaFuncGen";
import { StaticRefFuncGen } from "./generators/staticRefFuncGen";
 
export class MainContractGen implements Generator {
  gens = new Map<string, Generator>();
 
  constructor() {
    this.gens.set("header", new HeaderGen());
    this.gens.set("contractStart", new ContractStartGen());
    this.gens.set("constructor", new ConstructorGen());
    this.gens.set("metadataStruct", new MetadataStructGen());
    this.gens.set("memberVars", new MemberVarsGen());
    this.gens.set("generalFuncs", new GeneralFuncGen());
    this.gens.set("schemaFuncs", new SchemaFuncGen());
    this.gens.set("packFuncs", new PackFuncGen());
    this.gens.set("mintFuncs", new MintFuncGen());
    this.gens.set("fieldFuncs", new FieldFuncGen());
    this.gens.set("staticRefFuncs", new StaticRefFuncGen());
    this.gens.set("dynamicRefFuncs", new DynamicRefFuncGen());
    this.gens.set("overrides", new OverrideFuncGen());
    this.gens.set("contractEnd", new ContractEndGen());
    this.gens.set("patchFuncs", new PatchFuncGen());
    this.gens.set("nl", { gen: (schema: ContractSchema) => '\n' });
  }
 
  gen(schema: ContractSchema): string {
    return this.appendGens([
      "header",
      "nl",
      "contractStart",
      "nl",
      "metadataStruct",
      "nl",
      "memberVars",
      "constructor",
      "nl",
      "generalFuncs",
      "schemaFuncs",
      "nl",
      "patchFuncs",
      "packFuncs", 
      "mintFuncs", 
      "fieldFuncs", 
      "staticRefFuncs", 
      "dynamicRefFuncs", 
      "overrides", 
      "contractEnd"
    ], schema);
  }
 
  appendGens(names: string[], schema: ContractSchema): string {
    let output = "";
    for (let name of names) {
      output = this.appendGen(name, schema, output);
    }
    return output;
  }
 
  appendGen(name: string, schema: ContractSchema, output: string): string {
    return output + this.gens.get(name)?.gen(schema);
  }
}