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

Add questionable reducer tatic

parent 7ccdab06
No related branches found
No related tags found
No related merge requests found
Showing
with 205 additions and 16 deletions
......@@ -28,7 +28,7 @@ module ReduceC (
import Control.Applicative (Alternative (empty, (<|>)))
import Control.Monad (
MonadPlus (mzero),
MonadPlus (),
foldM,
forM,
guard,
......@@ -49,13 +49,10 @@ import Control.Monad.Reduce (
import Control.Monad.State (
MonadState (get, state),
MonadTrans (lift),
State,
StateT (runStateT),
evalState,
evalStateT,
gets,
modify',
runState,
)
import Control.Monad.Trans.Maybe (MaybeT (runMaybeT))
import Data.Foldable
......@@ -420,8 +417,7 @@ updateCDerivedDeclarators bt ff dd = do
C.CArrDeclr r as ni -> do
d' <- case as of
C.CArrSize _ _ -> do
-- b <- check ("remove array size", C.posOf ni)
let b = False
b <- check ("remove array size", C.posOf ni)
pure $ if b then C.CArrDeclr r (C.CNoArrSize False) ni else d
_ -> pure d
pure (NonVoid . TPointer $ t, d' : dd')
......@@ -497,9 +493,8 @@ reduceCExternalDeclaration r = case r of
-- TODO handle this edgecase (struct declared in function declaration)
_ <- reduceStructDeclaration spec
ctx' <- get
(bt, spec') <- joinLiftMaybe $ updateCDeclarationSpecifiers keepAll{sfKeepStatic = keepStatic} ctx' spec
((t', dd'), ctx'') <- runStateT (updateCDerivedDeclarators bt (fromMaybe (repeat True) (mfun >>= funParams)) dd) ctx'
(bt, spec') <- joinLiftMaybe $ updateCDeclarationSpecifiers keepAll{sfKeepStatic = keepStatic} ctx spec
((t', dd'), ctx'') <- runStateT (updateCDerivedDeclarators bt (fromMaybe (repeat True) (mfun >>= funParams)) dd) ctx
let t@(TFun (FunType rt _)) = nonVoid t'
......@@ -736,7 +731,7 @@ reduceCDeclarationItem bt nullable = \case
nullable
("remove initialization", C.posOf ni)
(pure Nothing)
(Just <$> reduceCInitializer t einit2 ctx)
(Just <$> reduceCInitializer t einit2 ctx True)
case getInlinable (fromMaybe einit2 einit') of
Just e' -> do
modify' (addInlineExpr vid (IEInline e'))
......@@ -773,8 +768,9 @@ reduceCInitializer ::
Type ->
C.CInitializer C.NodeInfo ->
Context ->
Bool ->
m (C.CInitializer C.NodeInfo)
reduceCInitializer t einit ctx = case einit of
reduceCInitializer t einit ctx toplevel = case einit of
C.CInitExpr e ni2 -> do
let me = reduceCExpr e (exactly t) ctx
case (me, t) of
......@@ -793,16 +789,30 @@ reduceCInitializer t einit ctx = case einit of
let fields = fieldsOfStruct ctx stct
let i'' = catMaybes $ zipWith (\(_, t') i -> (i,) <$> t') fields items
forM i'' \((p, r), t') -> do
r' <- reduceCInitializer t' r ctx
r' <- reduceCInitializer t' r ctx False
pure (p, r')
TPointer (NonVoid t')
| toplevel -> do
items' <- reverseRemoveList ni2 (reverse items)
forM (reverse items') \(p, r) -> do
r' <- reduceCInitializer t' r ctx False
pure (p, r')
TPointer (NonVoid t') -> do
| otherwise -> do
forM items \(p, r) -> do
r' <- reduceCInitializer t' r ctx
r' <- reduceCInitializer t' r ctx False
pure (p, r')
_ow ->
-- "Unexpected type of init list: " <> show t <> " at " <> show (C.posOf ni2)
pure items
pure $ C.CInitList (C.CInitializerList items') ni2
where
reverseRemoveList ni2 = \case
[] -> pure []
items@(_ : rst) -> do
b <- check ("remove the last item", C.posOf ni2)
if b
then reverseRemoveList ni2 rst
else pure items
reduceCCompoundBlockItem ::
(MonadReduce Lab m, HasCallStack) =>
......
int f();
int f() {
return f();
}
int main() {
return 0;
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
......
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
......
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[3][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[3][3] = { { 1, 2, 3 } };
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[3][3] = { };
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove initialization at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
......
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove initialization at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
......
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[][3] = { { 1, 2, 3 } };
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 0 delete variable at ("test/cases/small/array.c": line 1)
int a[][3] = { };
int main()
{
}
// 0 remove array size at ("test/cases/small/array.c": line 1)
// 1 remove array size at ("test/cases/small/array.c": line 1)
// 0 remove initialization at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 remove the last item at ("test/cases/small/array.c": line 1)
// 1 delete variable at ("test/cases/small/array.c": line 1)
int main()
{
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment