Skip to content
Snippets Groups Projects
Commit 15acce32 authored by chrg's avatar chrg
Browse files

Work work!

parent 0f54a4c2
No related branches found
No related tags found
No related merge requests found
Showing
with 185 additions and 43 deletions
......@@ -165,7 +165,10 @@ reduceCExternalDeclaration r ctx = case r of
pure (Just $ C.CFDefExt <$> reduceCFunDef fun ctx, ctx)
| otherwise ->
case functionName fun of
Just fid -> do
Just fid
| shouldDeleteFunction ctx fun -> do
pure (Nothing, addInlineExpr fid IEDelete ctx)
| otherwise -> do
let nctx =
ctx & foldr \case
(Just t, Just i) -> addInlineExpr i (IEKeep t)
......@@ -189,7 +192,10 @@ reduceCExternalDeclaration r ctx = case r of
( Just (C.CFDefExt <$> red fun' ps)
, addInlineExpr fid (IEKeep (CTFun (map fst ps))) ctx
)
Nothing ->
Nothing
| shouldDeleteFunction ctx fun -> do
pure (Nothing, ctx)
| otherwise -> do
split
("remove function", C.posOf r)
(pure (Nothing, ctx))
......@@ -600,21 +606,26 @@ reduceCStatement smt labs ctx = case smt of
C.CFor e1 e2 e3 s ni -> do
(me1', ctx') <- case e1 of
C.CForDecl d@(C.CDecl rec decl ni') -> do
(decl', ctx') <- foldr (reduceCDeclarationItem (shouldDeleteDeclaration ctx d) (ctype ctx rec)) (pure ([], ctx)) decl
(decl', ctx') <-
foldr
(reduceCDeclarationItem (shouldDeleteDeclaration ctx d) (ctype ctx rec))
(pure ([], ctx))
decl
res <-
if null decl'
then
whenSplit
(AllowEmptyDeclarations `isIn` ctx')
if AllowEmptyDeclarations `isIn` ctx'
then
split
("remove empty declaration", C.posOf ni')
(pure Nothing)
(pure $ Just $ C.CForDecl (C.CDecl rec decl' ni'))
else pure Nothing
else pure $ Just $ C.CForDecl (C.CDecl rec decl' ni')
pure (res, ctx')
C.CForInitializing e -> do
e' <- maybeSplit ("remove initializer", C.posOf ni) (e >>= \e' -> reduceCExpr e' ctx)
whenSplit
(AllowEmptyDeclarations `isIn` ctx)
split
("remove empty declaration", C.posOf ni)
(pure (Nothing, ctx))
(pure (Just $ C.CForInitializing e', ctx))
......@@ -867,10 +878,14 @@ inlineTypeDefsCDeclaration decl ctx =
C.CDecl (inlineTypeDefsSpecs items ctx) (map (`inlineTypeDefsCDI` ctx) decli) ni
a -> don'tHandle a
shouldDeleteFunction :: Context -> C.CFunctionDef C.NodeInfo -> Bool
shouldDeleteFunction ctx (C.CFunDef spec _ _ _ _) =
any (shouldDeleteDeclSpec ctx) spec
shouldDeleteDeclaration :: Context -> C.CDeclaration C.NodeInfo -> Bool
shouldDeleteDeclaration ctx decl =
case decl of
C.CDecl items decli _ -> any shouldDeleteDeclSpec items || any shouldDeleteDeclItem decli
C.CDecl items decli _ -> any (shouldDeleteDeclSpec ctx) items || any shouldDeleteDeclItem decli
a -> don'tHandle a
where
shouldDeleteDeclItem = \case
......@@ -887,7 +902,8 @@ shouldDeleteDeclaration ctx decl =
C.CPtrDeclr _ _ -> False
a -> don'tHandle a
shouldDeleteDeclSpec = \case
shouldDeleteDeclSpec :: Context -> C.CDeclarationSpecifier C.NodeInfo -> Bool
shouldDeleteDeclSpec ctx = \case
C.CTypeSpec (C.CSUType (C.CStruct _ (Just idx) Nothing _ _) _) ->
case Map.lookup idx . structs $ ctx of
Just ISDelete -> True
......
......@@ -3,6 +3,7 @@
// 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)
// 0 remove empty declaration at ("test/cases/small/for.c": line 4)
// 0 remove empty compound at ("test/cases/small/for.c": line 4)
static int a = 0;
......
......@@ -3,6 +3,7 @@
// 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)
// 0 remove empty declaration at ("test/cases/small/for.c": line 4)
// 1 remove empty compound at ("test/cases/small/for.c": line 4)
static int a = 0;
......
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 0 remove empty compound at ("test/cases/small/for.c": line 4)
// 0 remove the for loop at ("test/cases/small/for.c": line 4)
static int a = 0;
int main()
{
for (;;)
{
}
}
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 0 remove empty compound at ("test/cases/small/for.c": line 4)
// 1 remove the for loop at ("test/cases/small/for.c": line 4)
// 0 expand compound statment at ("test/cases/small/for.c": line 4)
static int a = 0;
int main()
{
{
}
}
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 0 remove empty compound at ("test/cases/small/for.c": line 4)
// 1 remove the for loop at ("test/cases/small/for.c": line 4)
// 1 expand compound statment at ("test/cases/small/for.c": line 4)
// 0 remove empty compound at ("test/cases/small/for.c": line 3)
static int a = 0;
int main()
{
}
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 0 remove empty compound at ("test/cases/small/for.c": line 4)
// 1 remove the for loop at ("test/cases/small/for.c": line 4)
// 1 expand compound statment at ("test/cases/small/for.c": line 4)
// 1 remove empty compound at ("test/cases/small/for.c": line 3)
static int a = 0;
int main()
{
}
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 1 remove empty compound at ("test/cases/small/for.c": line 4)
// 0 remove the for loop at ("test/cases/small/for.c": line 4)
static int a = 0;
int main()
{
for (;;)
{
}
}
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 1 remove empty compound at ("test/cases/small/for.c": line 4)
// 1 remove the for loop at ("test/cases/small/for.c": line 4)
// 0 expand compound statment at ("test/cases/small/for.c": line 4)
static int a = 0;
int main()
{
{
}
}
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 1 remove empty compound at ("test/cases/small/for.c": line 4)
// 1 remove the for loop at ("test/cases/small/for.c": line 4)
// 1 expand compound statment at ("test/cases/small/for.c": line 4)
// 0 remove empty compound at ("test/cases/small/for.c": line 3)
static int a = 0;
int main()
{
}
// 0 inline variable a at ("test/cases/small/for.c": line 1)
// 0 remove static at ("test/cases/small/for.c": line 1)
// 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)
// 1 remove empty declaration at ("test/cases/small/for.c": line 4)
// 1 remove empty compound at ("test/cases/small/for.c": line 4)
// 1 remove the for loop at ("test/cases/small/for.c": line 4)
// 1 expand compound statment at ("test/cases/small/for.c": line 4)
// 1 remove empty compound at ("test/cases/small/for.c": line 3)
static int a = 0;
int main()
{
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment