summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-11-21 13:18:01 -0500
committerJoe Crayne <joe@jerkface.net>2018-11-21 13:18:32 -0500
commit23fbc6d4afd3787f9e74df149d0235c6dbfd50fd (patch)
tree66d7bbe098729ed6961c85ef28ce4a812f9402d8
parente375eb43a36062a0106d3a7d6225751cb571a77c (diff)
wip: monkey-patch stub.
-rw-r--r--c2haskell.hs31
1 files changed, 25 insertions, 6 deletions
diff --git a/c2haskell.hs b/c2haskell.hs
index 847458c..7a345e6 100644
--- a/c2haskell.hs
+++ b/c2haskell.hs
@@ -458,7 +458,8 @@ c2haskell opts cs missings (CTranslUnit edecls _) = 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 $ show $ pretty $ makeSetter d
461 putStrLn $ take 2048 $ ppShow $ everywhere (mkT eraseNodeInfo) <$> makeFunctionPointer d 461 putStrLn $ show $ pretty $ makeStub d
462 putStrLn $ ppShow $ everywhere (mkT eraseNodeInfo) d -- <$> makeFunctionPointer d
462 463
463-- TODO: make idempotent 464-- TODO: make idempotent
464makeStatic :: [CDeclarationSpecifier NodeInfo] -> [CDeclarationSpecifier NodeInfo] 465makeStatic :: [CDeclarationSpecifier NodeInfo] -> [CDeclarationSpecifier NodeInfo]
@@ -511,6 +512,15 @@ changeArgList f (CFDefExt (CFunDef xs ys zs c d)) = CFDefExt (CFunDef xs (change
511changeArgList f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl xs (changeArgList2 f ys) pos)) 512changeArgList f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl xs (changeArgList2 f ys) pos))
512 513
513 514
515getArgList1 (CDeclr a xs b c d) = xs
516
517getArgList2 ((a,b,c):zs) = getArgList3 a
518
519getArgList3 (Just (CDeclr a x b c d)) = x
520
521getArgList (CFDefExt (CFunDef xs ys zs c d)) = getArgList1 ys
522getArgList (CDeclExt (CDecl xs ys pos)) = getArgList2 ys
523
514changeReturnValue f (CFDefExt (CFunDef xs ys zs c d)) = (CFDefExt (CFunDef (f xs) ys zs c d)) 524changeReturnValue f (CFDefExt (CFunDef xs ys zs c d)) = (CFDefExt (CFunDef (f xs) ys zs c d))
515changeReturnValue f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl (f xs) ys pos)) 525changeReturnValue f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl (f xs) ys pos))
516 526
@@ -522,21 +532,30 @@ setSetterBody name (CDeclExt (CDecl xs ys pos)) = (CFDefExt (CFunDef xs v [] (se
522 (Just y,_,_):_ -> y 532 (Just y,_,_):_ -> y
523 _ -> CDeclr Nothing [] Nothing [] pos 533 _ -> CDeclr Nothing [] Nothing [] pos
524 534
535makeStub d@(CDeclExt (CDecl xs ys pos)) =
536 let oargs:xs = getArgList d
537 (args,vs) = makeParameterNames oargs
538 in changeArgList (const $ args:xs) d
539
525parameterIdent :: CDeclaration a -> Maybe Ident 540parameterIdent :: CDeclaration a -> Maybe Ident
526parameterIdent (CDecl _ xs n) = listToMaybe $ do 541parameterIdent (CDecl _ xs n) = listToMaybe $ do
527 (Just (CDeclr (Just x) _ _ _ _),_,_) <- xs 542 (Just (CDeclr (Just x) _ _ _ _),_,_) <- xs
528 return x 543 return x
529 544
530makeParameterNames :: CDerivedDeclarator NodeInfo -> (CDerivedDeclarator NodeInfo,[CExpression NodeInfo]) 545makeParameterNames :: CDerivedDeclarator NodeInfo -> (CDerivedDeclarator NodeInfo,[CExpression NodeInfo])
531makeParameterNames (CFunDeclr (Right (CDecl rtyp ps n : ds, flg)) z2 z3) 546makeParameterNames (CFunDeclr (Right (ps, flg)) z2 z3)
532 = ( CFunDeclr (Right (CDecl rtyp qs n : ds, flg)) z2 z3 , [] ) 547 = ( CFunDeclr (Right (qs, flg)) z2 z3 , map expr qs )
533 -- FIXME: Each paramter gets its own CDecl.
534 where 548 where
549 -- TODO: ensure uniqueness of generated parameter names
535 qs = zipWith mkp [0..] ps 550 qs = zipWith mkp [0..] ps
536 mkp num (Just (CDeclr Nothing typ x ys z),a,b) = 551 mkp num (CDecl rtyp ((Just (CDeclr Nothing typ x ys z),a,b):xs) n)
537 (Just (CDeclr (Just $ mkidn num n) typ x ys z),a,b) 552 = (CDecl rtyp ((Just (CDeclr (Just $ mkidn num n) typ x ys z),a,b):xs) n)
553 mkp num (CDecl rtyp [] n)
554 = (CDecl rtyp ((Just (CDeclr (Just $ mkidn num n) [] Nothing [] n),Nothing,Nothing):[]) n)
538 mkp num p = p 555 mkp num p = p
539 556
557expr :: CDeclaration a -> CExpression a
558expr (CDecl rtyp ((Just (CDeclr (Just i) typ x ys z),a,b):xs) n) = CVar i n
540 559
541mkidn :: Show a => a -> NodeInfo -> Ident 560mkidn :: Show a => a -> NodeInfo -> Ident
542mkidn num n = C.Ident ("a"++show num) 0 n 561mkidn num n = C.Ident ("a"++show num) 0 n