From bbb723010146f84fe332aa7cb5cf2d3bdcc20ff9 Mon Sep 17 00:00:00 2001 From: Christian Gram Kalhauge <chrg@dtu.dk> Date: Wed, 28 Feb 2024 15:18:43 +0100 Subject: [PATCH] Fix many problems --- flake.nix | 2 +- rtree-c/src/ReduceC.hs | 5 +++-- rtree-c/test/cases/small/for.c | 6 ++++++ rtree-c/test/expected/for/main.c | 7 +++++++ rtree-c/test/expected/for/reduction/r00000.c | 13 +++++++++++++ rtree-c/test/expected/for/reduction/r00001.c | 13 +++++++++++++ rtree-c/test/expected/for/reduction/r0001.c | 12 ++++++++++++ rtree-c/test/expected/for/reduction/r001.c | 11 +++++++++++ rtree-c/test/expected/for/reduction/r01.c | 7 +++++++ rtree-c/test/expected/for/reduction/r10.c | 9 +++++++++ rtree-c/test/expected/for/reduction/r11.c | 6 ++++++ 11 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 rtree-c/test/cases/small/for.c create mode 100644 rtree-c/test/expected/for/main.c create mode 100644 rtree-c/test/expected/for/reduction/r00000.c create mode 100644 rtree-c/test/expected/for/reduction/r00001.c create mode 100644 rtree-c/test/expected/for/reduction/r0001.c create mode 100644 rtree-c/test/expected/for/reduction/r001.c create mode 100644 rtree-c/test/expected/for/reduction/r01.c create mode 100644 rtree-c/test/expected/for/reduction/r10.c create mode 100644 rtree-c/test/expected/for/reduction/r11.c diff --git a/flake.nix b/flake.nix index f167b19..ba4cb19 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 3a0b874..f95c80c 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 0000000..8180742 --- /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 0000000..e598d6a --- /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 0000000..6dae1ca --- /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 0000000..887d0d8 --- /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 0000000..6f81f09 --- /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 0000000..9262883 --- /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 0000000..b0bd08b --- /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 0000000..5168b51 --- /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 0000000..6756efd --- /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() +{ +} -- GitLab