diff --git a/flake.nix b/flake.nix index f167b1972465eff1642548c13135ececcc70b667..ba4cb19a8189ba4fafab8f9bdf41844a3cf2bd23 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ p.callCabal2nixWithOptions n (nix-filter.lib {root = "${self}/${n}";}) "" {}; packages = lib: p: { - "language-c" = p.callCabal2nixWithOptions "language-c" inputs.language-c "" {}; + "language-c" = lib.dontCheck (p.callCabal2nixWithOptions "language-c" inputs.language-c "" {}); "hspec-glitter" = p.callCabal2nixWithOptions "hspec-glitter" inputs.hspec-glitter "" {}; "rtree" = lib.dontCheck (load p "rtree"); "rtree-c" = lib.dontCheck (load p "rtree-c"); diff --git a/rtree-c/src/ReduceC.hs b/rtree-c/src/ReduceC.hs index 3a0b874ba448004a96ced3ec67fced905ef7b43b..f95c80cc89ae51e0cd7661833883de0a6d582632 100644 --- a/rtree-c/src/ReduceC.hs +++ b/rtree-c/src/ReduceC.hs @@ -348,12 +348,13 @@ reduceCStatement smt ctx = case smt of (pure $ Just $ C.CForDecl (C.CDecl rec decl' ni')) else pure $ Just $ C.CForDecl (C.CDecl rec decl' ni') pure (res, ctx') - C.CForInitializing e -> + C.CForInitializing e -> do + e' <- maybeSplit ("remove initializer", C.posOf ni) (e >>= \e' -> reduceCExpr e' ctx) whenSplit (AllowEmptyDeclarations `isIn` ctx) ("remove empty declaration", C.posOf ni) (pure (Nothing, ctx)) - (pure (Just $ C.CForInitializing e, ctx)) + (pure (Just $ C.CForInitializing e', ctx)) d -> don'tHandle d s' <- reduceCStatementOrEmptyBlock s ctx' diff --git a/rtree-c/test/cases/small/for.c b/rtree-c/test/cases/small/for.c new file mode 100644 index 0000000000000000000000000000000000000000..81807423f9f4591e31f27d480dddfb96eb9b411a --- /dev/null +++ b/rtree-c/test/cases/small/for.c @@ -0,0 +1,6 @@ +static int a = 0; + +int main () { + for (a = 0;;) { + } +} diff --git a/rtree-c/test/expected/for/main.c b/rtree-c/test/expected/for/main.c new file mode 100644 index 0000000000000000000000000000000000000000..e598d6aefa947454e199c2b2cf2dd080eaf791a0 --- /dev/null +++ b/rtree-c/test/expected/for/main.c @@ -0,0 +1,7 @@ +static int a = 0; +int main() +{ + for (a = 0;;) + { + } +} diff --git a/rtree-c/test/expected/for/reduction/r00000.c b/rtree-c/test/expected/for/reduction/r00000.c new file mode 100644 index 0000000000000000000000000000000000000000..6dae1cadae1d020c8c8b89dd273255e4e9bb2e31 --- /dev/null +++ b/rtree-c/test/expected/for/reduction/r00000.c @@ -0,0 +1,13 @@ +// 0 inline variable a at ("test/cases/small/for.c": line 1) +// 0 remove statement at ("test/cases/small/for.c": line 4) +// 0 remove initializer at ("test/cases/small/for.c": line 4) +// 0 reduce to left at ("test/cases/small/for.c": line 4) +// 0 reduce to right at ("test/cases/small/for.c": line 4) + +static int a = 0; +int main() +{ + for (a = 0;;) + { + } +} diff --git a/rtree-c/test/expected/for/reduction/r00001.c b/rtree-c/test/expected/for/reduction/r00001.c new file mode 100644 index 0000000000000000000000000000000000000000..887d0d8d8265aaa87571f67e24ce7edad5fc7e78 --- /dev/null +++ b/rtree-c/test/expected/for/reduction/r00001.c @@ -0,0 +1,13 @@ +// 0 inline variable a at ("test/cases/small/for.c": line 1) +// 0 remove statement at ("test/cases/small/for.c": line 4) +// 0 remove initializer at ("test/cases/small/for.c": line 4) +// 0 reduce to left at ("test/cases/small/for.c": line 4) +// 1 reduce to right at ("test/cases/small/for.c": line 4) + +static int a = 0; +int main() +{ + for (0;;) + { + } +} diff --git a/rtree-c/test/expected/for/reduction/r0001.c b/rtree-c/test/expected/for/reduction/r0001.c new file mode 100644 index 0000000000000000000000000000000000000000..6f81f095c62c52930c748f64446c2fecf3e696ab --- /dev/null +++ b/rtree-c/test/expected/for/reduction/r0001.c @@ -0,0 +1,12 @@ +// 0 inline variable a at ("test/cases/small/for.c": line 1) +// 0 remove statement at ("test/cases/small/for.c": line 4) +// 0 remove initializer at ("test/cases/small/for.c": line 4) +// 1 reduce to left at ("test/cases/small/for.c": line 4) + +static int a = 0; +int main() +{ + for (a;;) + { + } +} diff --git a/rtree-c/test/expected/for/reduction/r001.c b/rtree-c/test/expected/for/reduction/r001.c new file mode 100644 index 0000000000000000000000000000000000000000..9262883ee50cd2ae7aede947fffcb15f36bef4c5 --- /dev/null +++ b/rtree-c/test/expected/for/reduction/r001.c @@ -0,0 +1,11 @@ +// 0 inline variable a at ("test/cases/small/for.c": line 1) +// 0 remove statement at ("test/cases/small/for.c": line 4) +// 1 remove initializer at ("test/cases/small/for.c": line 4) + +static int a = 0; +int main() +{ + for (;;) + { + } +} diff --git a/rtree-c/test/expected/for/reduction/r01.c b/rtree-c/test/expected/for/reduction/r01.c new file mode 100644 index 0000000000000000000000000000000000000000..b0bd08b132a0872113642aad973dff18c1b2db83 --- /dev/null +++ b/rtree-c/test/expected/for/reduction/r01.c @@ -0,0 +1,7 @@ +// 0 inline variable a at ("test/cases/small/for.c": line 1) +// 1 remove statement at ("test/cases/small/for.c": line 4) + +static int a = 0; +int main() +{ +} diff --git a/rtree-c/test/expected/for/reduction/r10.c b/rtree-c/test/expected/for/reduction/r10.c new file mode 100644 index 0000000000000000000000000000000000000000..5168b516d2ac94b5a3a55066cea18448750d9263 --- /dev/null +++ b/rtree-c/test/expected/for/reduction/r10.c @@ -0,0 +1,9 @@ +// 1 inline variable a at ("test/cases/small/for.c": line 1) +// 0 remove statement at ("test/cases/small/for.c": line 4) + +int main() +{ + for (;;) + { + } +} diff --git a/rtree-c/test/expected/for/reduction/r11.c b/rtree-c/test/expected/for/reduction/r11.c new file mode 100644 index 0000000000000000000000000000000000000000..6756efdd7c2db285572b9e319a99f443176bea04 --- /dev/null +++ b/rtree-c/test/expected/for/reduction/r11.c @@ -0,0 +1,6 @@ +// 1 inline variable a at ("test/cases/small/for.c": line 1) +// 1 remove statement at ("test/cases/small/for.c": line 4) + +int main() +{ +}