1 /** 2 Copyright: Copyright (c) 2018, Joakim Brännström. All rights reserved. 3 License: MPL-2 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 6 This Source Code Form is subject to the terms of the Mozilla Public License, 7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain 8 one at http://mozilla.org/MPL/2.0/. 9 */ 10 module dextool.plugin.mutate.backend.mutation_type; 11 12 import dextool.plugin.mutate.backend.type; 13 import dextool.plugin.mutate.type : MutationKind; 14 15 public import dextool.plugin.mutate.backend.mutation_type.aor; 16 public import dextool.plugin.mutate.backend.mutation_type.aors; 17 public import dextool.plugin.mutate.backend.mutation_type.dcr; 18 public import dextool.plugin.mutate.backend.mutation_type.lcr; 19 public import dextool.plugin.mutate.backend.mutation_type.lcrb; 20 public import dextool.plugin.mutate.backend.mutation_type.ror; 21 public import dextool.plugin.mutate.backend.mutation_type.sdl; 22 public import dextool.plugin.mutate.backend.mutation_type.uoi; 23 24 @safe: 25 26 Mutation.Kind[] toInternal(const MutationKind[] k) @safe pure nothrow { 27 import std.algorithm : map, joiner; 28 import std.array : array; 29 import std.traits : EnumMembers; 30 31 auto kinds(const MutationKind k) { 32 final switch (k) with (MutationKind) { 33 case all: 34 return [EnumMembers!(Mutation.Kind)]; 35 case ror: 36 return rorMutationsAll.dup; 37 case rorp: 38 return rorpMutationsAll.dup; 39 case lcr: 40 return lcrMutationsAll.dup; 41 case aor: 42 return aorMutationsAll.dup ~ aorAssignMutationsAll; 43 case aors: 44 return aorsMutationsAll.dup ~ aorsAssignMutationsAll; 45 case uoi: 46 return uoiLvalueMutations; 47 case sdl: 48 return stmtDelMutations; 49 case dcr: 50 return dcrMutationsAll.dup; 51 case lcrb: 52 return lcrbMutationsAll.dup ~ lcrbAssignMutationsAll.dup; 53 } 54 } 55 56 return (k is null ? [MutationKind.all] : k).map!(a => kinds(a)).joiner.array; 57 } 58 59 /// Convert the internal mutation kind to those that are presented to the user via the CLI. 60 MutationKind toUser(Mutation.Kind k) @safe nothrow { 61 return fromInteralKindToUserKind[k]; 62 } 63 64 private: 65 66 immutable MutationKind[Mutation.Kind] fromInteralKindToUserKind; 67 68 shared static this() { 69 import std.traits : EnumMembers; 70 71 static foreach (const user_kind; EnumMembers!MutationKind) { 72 foreach (const internal_kind; toInternal([user_kind])) { 73 fromInteralKindToUserKind[internal_kind] = user_kind; 74 } 75 } 76 }