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.cr; 18 public import dextool.plugin.mutate.backend.mutation_type.dcr; 19 public import dextool.plugin.mutate.backend.mutation_type.lcr; 20 public import dextool.plugin.mutate.backend.mutation_type.lcrb; 21 public import dextool.plugin.mutate.backend.mutation_type.ror; 22 public import dextool.plugin.mutate.backend.mutation_type.sdl; 23 public import dextool.plugin.mutate.backend.mutation_type.uoi; 24 25 @safe: 26 27 Mutation.Kind[] toInternal(const MutationKind[] k) @safe pure nothrow { 28 import std.algorithm : map, joiner; 29 import std.array : array; 30 import std.traits : EnumMembers; 31 32 auto kinds(const MutationKind k) { 33 final switch (k) with (MutationKind) { 34 case all: 35 return [EnumMembers!(Mutation.Kind)]; 36 case ror: 37 return rorMutationsAll.dup; 38 case rorp: 39 return rorpMutationsAll.dup; 40 case lcr: 41 return lcrMutationsAll.dup; 42 case aor: 43 return aorMutationsAll.dup ~ aorAssignMutationsAll; 44 case aors: 45 return aorsMutationsAll.dup ~ aorsAssignMutationsAll; 46 case uoi: 47 return uoiLvalueMutations; 48 case sdl: 49 return stmtDelMutations; 50 case dcr: 51 return dcrMutationsAll.dup; 52 case lcrb: 53 return lcrbMutationsAll.dup ~ lcrbAssignMutationsAll.dup; 54 case cr: 55 return crMutationsAll.dup; 56 } 57 } 58 59 return (k is null ? [MutationKind.all] : k).map!(a => kinds(a)).joiner.array; 60 } 61 62 /// Convert the internal mutation kind to those that are presented to the user via the CLI. 63 MutationKind toUser(Mutation.Kind k) @safe nothrow { 64 return fromInteralKindToUserKind[k]; 65 } 66 67 private: 68 69 immutable MutationKind[Mutation.Kind] fromInteralKindToUserKind; 70 71 shared static this() { 72 import std.traits : EnumMembers; 73 74 static foreach (const user_kind; EnumMembers!MutationKind) { 75 foreach (const internal_kind; toInternal([user_kind])) { 76 fromInteralKindToUserKind[internal_kind] = user_kind; 77 } 78 } 79 }