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.lcr;
11 
12 import dextool.plugin.mutate.backend.type;
13 import dextool.clang_extensions : OpKind;
14 
15 auto lcrMutations(OpKind k) @safe pure nothrow {
16     import std.typecons : Tuple;
17 
18     alias Rval = Tuple!(Mutation.Kind[], "op", Mutation.Kind[], "expr");
19 
20     auto v = k in isLcr;
21     if (v is null)
22         return Rval();
23 
24     auto rval = Rval(null, [Mutation.Kind.lcrTrue, Mutation.Kind.lcrFalse]);
25 
26     if (*v == Mutation.Kind.lcrAnd) {
27         rval.op = [Mutation.Kind.lcrOr];
28     } else if (*v == Mutation.Kind.lcrOr) {
29         rval.op = [Mutation.Kind.lcrAnd];
30     }
31 
32     return rval;
33 }
34 
35 auto lcrLhsMutations(OpKind k) @safe pure nothrow {
36     return k in isLcr ? [Mutation.Kind.lcrLhs] : null;
37 }
38 
39 auto lcrRhsMutations(OpKind k) @safe pure nothrow {
40     return k in isLcr ? [Mutation.Kind.lcrRhs] : null;
41 }
42 
43 immutable Mutation.Kind[OpKind] isLcr;
44 
45 immutable Mutation.Kind[] lcrMutationsAll;
46 
47 shared static this() {
48     // dfmt off
49     with (OpKind) {
50     isLcr = cast(immutable)[
51         LAnd : Mutation.Kind.lcrAnd, // "&&"
52         LOr : Mutation.Kind.lcrOr, // "||"
53         OO_AmpAmp : Mutation.Kind.lcrAnd, // "&&"
54         OO_PipePipe : Mutation.Kind.lcrOr, // "||"
55     ];
56     }
57     // dfmt on
58 
59     with (Mutation.Kind) {
60         lcrMutationsAll = [lcrAnd, lcrOr, lcrLhs, lcrRhs, lcrTrue, lcrFalse];
61     }
62 }