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

Add declaration and definition case

parent b135f8a8
No related branches found
No related tags found
No related merge requests found
Showing
with 198 additions and 12 deletions
......@@ -16,10 +16,12 @@
nix-filter,
...
} @ inputs: let
load = p: n: {
load = final: p: n: {
"${n}" =
p.callCabal2nixWithOptions n
(nix-filter.lib {root = "${self}/${n}";}) "" {};
final.haskell.lib.overrideCabal
(p.callCabal2nixWithOptions n (nix-filter.lib {root = "${self}/${n}";}) "" {}) {
doCheck = true;
};
};
packages = final: p:
{
......@@ -29,8 +31,8 @@
doCheck = false;
};
}
// load p "rtree"
// load p "rtree-c";
// load final p "rtree"
// load final p "rtree-c";
overlays = final: prev: {
haskellPackages = prev.haskellPackages.extend (p: _: packages final p);
};
......@@ -67,8 +69,12 @@
hpkgs.shellFor
{
name = "rtree-shells";
packages = p: [p.rtree p.rtree-c];
packages = p: [
p.rtree
p.rtree-c
];
doBenchmark = true;
doCheck = true;
inherit nativeBuildInputs withHoogle;
};
};
......
......@@ -121,7 +121,9 @@ reduceCExternalDeclaration r cont ctx = do
| otherwise ->
split ("remove function " <> maybe "" C.identToString (functionName fun), C.posOf r) (cont ctx) do
r' <- C.CFDefExt <$> reduceCFunDef fun ctx
(r' :) <$> cont ctx
(r' :) <$> case functionName fun of
Just fid -> cont (addInlineExpr fid (C.CVar fid C.undefNode) ctx)
Nothing -> cont ctx
C.CDeclExt result ->
case result of
-- A typedef
......@@ -206,7 +208,7 @@ reduceCDeclarationItem d ma = case d of
, addInlineExpr i (C.CVar i ni) ctx
)
)
C.CDeclarationItem (C.CDeclr (Just i) [] Nothing [] ni) Nothing Nothing -> do
C.CDeclarationItem (C.CDeclr (Just i) _ Nothing [] ni) Nothing Nothing -> do
(ds, ctx) <- ma
split
("remove variable " <> C.identToString i, C.posOf ni)
......@@ -417,12 +419,14 @@ reduceCExpr expr ctx = case expr of
Just $ split ("reduce to operant", C.posOf expr) elhs' do
e <- elhs'
pure $ C.CUnary o e ni
C.CCall e es ni -> do
re <- reduceCExpr e (addKeyword DisallowVariableInlining ctx)
Just $ do
e' <- re
es' <- traverse (`reduceCExprOrZero` ctx) es
pure $ C.CCall e' es' ni
a -> error (show a)
-- C.CCall e es ni -> do
-- e' <- reduce e
-- es' <- traverse (fmap orZero reduce) es
-- pure $ C.CCall e' es' ni
-- C.CCond ec et ef ni -> do
-- ec' <- reduce ec
-- ef' <- reduce ef
......
int printf(const char *, ...);
int main () {
printf("Hello, World!");
}
int f() {
return 0;
}
int main() {
return f();
}
int printf(const char *, ...);
int main()
{
printf("Hello, World!");
}
// 0 remove variable printf at ("test/cases/small/declaration.c": line 1)
// 0 remove statement at ("test/cases/small/declaration.c": line 4)
// 0 replace by zero at ("test/cases/small/declaration.c": line 4)
int printf(const char *, ...);
int main()
{
printf("Hello, World!");
}
// 0 remove variable printf at ("test/cases/small/declaration.c": line 1)
// 0 remove statement at ("test/cases/small/declaration.c": line 4)
// 1 replace by zero at ("test/cases/small/declaration.c": line 4)
int printf(const char *, ...);
int main()
{
printf(0);
}
// 0 remove variable printf at ("test/cases/small/declaration.c": line 1)
// 1 remove statement at ("test/cases/small/declaration.c": line 4)
int printf(const char *, ...);
int main()
{
}
// 1 remove variable printf at ("test/cases/small/declaration.c": line 1)
int main()
{
}
int f()
{
return 0;
}
int main()
{
return f();
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 0 remove statement at ("test/cases/small/definition.c": line 2)
// 0 replace by zero at ("test/cases/small/definition.c": line 2)
// 0 remove statement at ("test/cases/small/definition.c": line 6)
// 0 replace by zero at ("test/cases/small/definition.c": line 6)
int f()
{
return 0;
}
int main()
{
return f();
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 0 remove statement at ("test/cases/small/definition.c": line 2)
// 0 replace by zero at ("test/cases/small/definition.c": line 2)
// 0 remove statement at ("test/cases/small/definition.c": line 6)
// 1 replace by zero at ("test/cases/small/definition.c": line 6)
int f()
{
return 0;
}
int main()
{
return 0;
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 0 remove statement at ("test/cases/small/definition.c": line 2)
// 0 replace by zero at ("test/cases/small/definition.c": line 2)
// 1 remove statement at ("test/cases/small/definition.c": line 6)
int f()
{
return 0;
}
int main()
{
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 0 remove statement at ("test/cases/small/definition.c": line 2)
// 1 replace by zero at ("test/cases/small/definition.c": line 2)
// 0 remove statement at ("test/cases/small/definition.c": line 6)
// 0 replace by zero at ("test/cases/small/definition.c": line 6)
int f()
{
return 0;
}
int main()
{
return f();
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 0 remove statement at ("test/cases/small/definition.c": line 2)
// 1 replace by zero at ("test/cases/small/definition.c": line 2)
// 0 remove statement at ("test/cases/small/definition.c": line 6)
// 1 replace by zero at ("test/cases/small/definition.c": line 6)
int f()
{
return 0;
}
int main()
{
return 0;
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 0 remove statement at ("test/cases/small/definition.c": line 2)
// 1 replace by zero at ("test/cases/small/definition.c": line 2)
// 1 remove statement at ("test/cases/small/definition.c": line 6)
int f()
{
return 0;
}
int main()
{
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 1 remove statement at ("test/cases/small/definition.c": line 2)
// 0 remove statement at ("test/cases/small/definition.c": line 6)
// 0 replace by zero at ("test/cases/small/definition.c": line 6)
int f()
{
}
int main()
{
return f();
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 1 remove statement at ("test/cases/small/definition.c": line 2)
// 0 remove statement at ("test/cases/small/definition.c": line 6)
// 1 replace by zero at ("test/cases/small/definition.c": line 6)
int f()
{
}
int main()
{
return 0;
}
// 0 remove function f at ("test/cases/small/definition.c": line 1)
// 1 remove statement at ("test/cases/small/definition.c": line 2)
// 1 remove statement at ("test/cases/small/definition.c": line 6)
int f()
{
}
int main()
{
}
// 1 remove function f at ("test/cases/small/definition.c": line 1)
// 0 remove statement at ("test/cases/small/definition.c": line 6)
int main()
{
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment