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

Work work!

parent 0f54a4c2
Branches
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 ...@@ -165,7 +165,10 @@ reduceCExternalDeclaration r ctx = case r of
pure (Just $ C.CFDefExt <$> reduceCFunDef fun ctx, ctx) pure (Just $ C.CFDefExt <$> reduceCFunDef fun ctx, ctx)
| otherwise -> | otherwise ->
case functionName fun of case functionName fun of
Just fid -> do Just fid
| shouldDeleteFunction ctx fun -> do
pure (Nothing, addInlineExpr fid IEDelete ctx)
| otherwise -> do
let nctx = let nctx =
ctx & foldr \case ctx & foldr \case
(Just t, Just i) -> addInlineExpr i (IEKeep t) (Just t, Just i) -> addInlineExpr i (IEKeep t)
...@@ -189,7 +192,10 @@ reduceCExternalDeclaration r ctx = case r of ...@@ -189,7 +192,10 @@ reduceCExternalDeclaration r ctx = case r of
( Just (C.CFDefExt <$> red fun' ps) ( Just (C.CFDefExt <$> red fun' ps)
, addInlineExpr fid (IEKeep (CTFun (map fst ps))) ctx , addInlineExpr fid (IEKeep (CTFun (map fst ps))) ctx
) )
Nothing -> Nothing
| shouldDeleteFunction ctx fun -> do
pure (Nothing, ctx)
| otherwise -> do
split split
("remove function", C.posOf r) ("remove function", C.posOf r)
(pure (Nothing, ctx)) (pure (Nothing, ctx))
...@@ -600,21 +606,26 @@ reduceCStatement smt labs ctx = case smt of ...@@ -600,21 +606,26 @@ reduceCStatement smt labs ctx = case smt of
C.CFor e1 e2 e3 s ni -> do C.CFor e1 e2 e3 s ni -> do
(me1', ctx') <- case e1 of (me1', ctx') <- case e1 of
C.CForDecl d@(C.CDecl rec decl ni') -> do 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 <- res <-
if null decl' if null decl'
then then
whenSplit if AllowEmptyDeclarations `isIn` ctx'
(AllowEmptyDeclarations `isIn` ctx') then
split
("remove empty declaration", C.posOf ni') ("remove empty declaration", C.posOf ni')
(pure Nothing) (pure Nothing)
(pure $ Just $ C.CForDecl (C.CDecl rec decl' ni')) (pure $ Just $ C.CForDecl (C.CDecl rec decl' ni'))
else pure Nothing
else pure $ Just $ C.CForDecl (C.CDecl rec decl' ni') else pure $ Just $ C.CForDecl (C.CDecl rec decl' ni')
pure (res, ctx') pure (res, ctx')
C.CForInitializing e -> do C.CForInitializing e -> do
e' <- maybeSplit ("remove initializer", C.posOf ni) (e >>= \e' -> reduceCExpr e' ctx) e' <- maybeSplit ("remove initializer", C.posOf ni) (e >>= \e' -> reduceCExpr e' ctx)
whenSplit split
(AllowEmptyDeclarations `isIn` ctx)
("remove empty declaration", C.posOf ni) ("remove empty declaration", C.posOf ni)
(pure (Nothing, ctx)) (pure (Nothing, ctx))
(pure (Just $ C.CForInitializing e', ctx)) (pure (Just $ C.CForInitializing e', ctx))
...@@ -867,10 +878,14 @@ inlineTypeDefsCDeclaration decl ctx = ...@@ -867,10 +878,14 @@ inlineTypeDefsCDeclaration decl ctx =
C.CDecl (inlineTypeDefsSpecs items ctx) (map (`inlineTypeDefsCDI` ctx) decli) ni C.CDecl (inlineTypeDefsSpecs items ctx) (map (`inlineTypeDefsCDI` ctx) decli) ni
a -> don'tHandle a 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 :: Context -> C.CDeclaration C.NodeInfo -> Bool
shouldDeleteDeclaration ctx decl = shouldDeleteDeclaration ctx decl =
case decl of 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 a -> don'tHandle a
where where
shouldDeleteDeclItem = \case shouldDeleteDeclItem = \case
...@@ -887,7 +902,8 @@ shouldDeleteDeclaration ctx decl = ...@@ -887,7 +902,8 @@ shouldDeleteDeclaration ctx decl =
C.CPtrDeclr _ _ -> False C.CPtrDeclr _ _ -> False
a -> don'tHandle a 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 _ _) _) -> C.CTypeSpec (C.CSUType (C.CStruct _ (Just idx) Nothing _ _) _) ->
case Map.lookup idx . structs $ ctx of case Map.lookup idx . structs $ ctx of
Just ISDelete -> True Just ISDelete -> True
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// 0 remove initializer 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 left at ("test/cases/small/for.c": line 4)
// 0 reduce to right 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) // 0 remove empty compound at ("test/cases/small/for.c": line 4)
static int a = 0; static int a = 0;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// 0 remove initializer 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 left at ("test/cases/small/for.c": line 4)
// 0 reduce to right 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) // 1 remove empty compound at ("test/cases/small/for.c": line 4)
static int a = 0; 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