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