summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-11-20 23:27:57 -0500
committerJoe Crayne <joe@jerkface.net>2018-11-20 23:27:57 -0500
commita59351a64b8cb9ad7fb208281b6f3232c62f2afe (patch)
tree8d62c0a4a1c3b90d3b62c4a61a1b60b29ede71e6
parent86ce08d89199ae3ec142da4c83cdc7ab308e85f7 (diff)
wip: monkey-patch setter. Argument list only.
-rw-r--r--c2haskell.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/c2haskell.hs b/c2haskell.hs
index 4f2644b..0e03cd7 100644
--- a/c2haskell.hs
+++ b/c2haskell.hs
@@ -457,6 +457,7 @@ c2haskell opts cs missings (CTranslUnit edecls _) = do
457 forM_ (take 1 $ symbolSource si) $ \d -> do 457 forM_ (take 1 $ symbolSource si) $ \d -> do
458 putStrLn $ show $ pretty d 458 putStrLn $ show $ pretty d
459 putStrLn $ show $ pretty $ makeFunctionPointer d 459 putStrLn $ show $ pretty $ makeFunctionPointer d
460 putStrLn $ show $ pretty $ makeSetter d
460 putStrLn $ take 2048 $ ppShow $ everywhere (mkT eraseNodeInfo) <$> makeFunctionPointer d 461 putStrLn $ take 2048 $ ppShow $ everywhere (mkT eraseNodeInfo) <$> makeFunctionPointer d
461 462
462-- TODO: make idempotent 463-- TODO: make idempotent
@@ -496,6 +497,41 @@ changeName f d = d
496makeAcceptableDecl (HS.TypeDecl a (DHead b (HS.Ident c signame)) ftyp) 497makeAcceptableDecl (HS.TypeDecl a (DHead b (HS.Ident c signame)) ftyp)
497 = (HS.TypeDecl a (DHead b (HS.Ident c signame)) (makeFunctionUseIO $ makeAcceptableImport ftyp)) 498 = (HS.TypeDecl a (DHead b (HS.Ident c signame)) (makeFunctionUseIO $ makeAcceptableImport ftyp))
498 499
500makeSetter d@(CDeclExt (CDecl xs ys pos)) = changeArgList (const voidp) $ changeName ("setf_"++) d
501
502changeArgList1 f (CDeclr a xs b c d) = CDeclr a (f xs) b c d
503
504changeArgList2 f ((a,b,c):zs) = (changeArgList3 f a,b,c):zs
505
506changeArgList3 f (Just (CDeclr a x b c d)) = Just (CDeclr a (f x) b c d)
507
508changeArgList f (CFDefExt (CFunDef xs ys zs c d)) = CFDefExt (CFunDef xs (changeArgList1 f ys) zs c d)
509changeArgList f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl xs (changeArgList2 f ys) pos))
510
511
512voidp :: [CDerivedDeclarator NodeInfo]
513voidp = [ CFunDeclr
514 (Right ( [ CDecl
515 [ CTypeSpec (CVoidType n) ]
516 [ ( Just (CDeclr
517 (Just (C.Ident "p" 0 n))
518 [ CPtrDeclr [] n ]
519 Nothing
520 []
521 n)
522 , Nothing
523 , Nothing
524 )
525 ]
526 n
527 ]
528 , False
529 ))
530 []
531 n]
532 where n = undefNode
533
534
499goMissing db cfun = do 535goMissing db cfun = do
500 forM_ (Map.lookup cfun $ syms db) $ \si -> do 536 forM_ (Map.lookup cfun $ syms db) $ \si -> do
501 forM_ (take 1 $ symbolSource si) $ \d -> do 537 forM_ (take 1 $ symbolSource si) $ \d -> do