diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-21 13:18:01 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-21 13:18:32 -0500 |
commit | 23fbc6d4afd3787f9e74df149d0235c6dbfd50fd (patch) | |
tree | 66d7bbe098729ed6961c85ef28ce4a812f9402d8 | |
parent | e375eb43a36062a0106d3a7d6225751cb571a77c (diff) |
wip: monkey-patch stub.
-rw-r--r-- | c2haskell.hs | 31 |
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 |
464 | makeStatic :: [CDeclarationSpecifier NodeInfo] -> [CDeclarationSpecifier NodeInfo] | 465 | makeStatic :: [CDeclarationSpecifier NodeInfo] -> [CDeclarationSpecifier NodeInfo] |
@@ -511,6 +512,15 @@ changeArgList f (CFDefExt (CFunDef xs ys zs c d)) = CFDefExt (CFunDef xs (change | |||
511 | changeArgList f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl xs (changeArgList2 f ys) pos)) | 512 | changeArgList f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl xs (changeArgList2 f ys) pos)) |
512 | 513 | ||
513 | 514 | ||
515 | getArgList1 (CDeclr a xs b c d) = xs | ||
516 | |||
517 | getArgList2 ((a,b,c):zs) = getArgList3 a | ||
518 | |||
519 | getArgList3 (Just (CDeclr a x b c d)) = x | ||
520 | |||
521 | getArgList (CFDefExt (CFunDef xs ys zs c d)) = getArgList1 ys | ||
522 | getArgList (CDeclExt (CDecl xs ys pos)) = getArgList2 ys | ||
523 | |||
514 | changeReturnValue f (CFDefExt (CFunDef xs ys zs c d)) = (CFDefExt (CFunDef (f xs) ys zs c d)) | 524 | changeReturnValue f (CFDefExt (CFunDef xs ys zs c d)) = (CFDefExt (CFunDef (f xs) ys zs c d)) |
515 | changeReturnValue f (CDeclExt (CDecl xs ys pos)) = (CDeclExt (CDecl (f xs) ys pos)) | 525 | changeReturnValue 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 | ||
535 | makeStub 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 | |||
525 | parameterIdent :: CDeclaration a -> Maybe Ident | 540 | parameterIdent :: CDeclaration a -> Maybe Ident |
526 | parameterIdent (CDecl _ xs n) = listToMaybe $ do | 541 | parameterIdent (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 | ||
530 | makeParameterNames :: CDerivedDeclarator NodeInfo -> (CDerivedDeclarator NodeInfo,[CExpression NodeInfo]) | 545 | makeParameterNames :: CDerivedDeclarator NodeInfo -> (CDerivedDeclarator NodeInfo,[CExpression NodeInfo]) |
531 | makeParameterNames (CFunDeclr (Right (CDecl rtyp ps n : ds, flg)) z2 z3) | 546 | makeParameterNames (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 | ||
557 | expr :: CDeclaration a -> CExpression a | ||
558 | expr (CDecl rtyp ((Just (CDeclr (Just i) typ x ys z),a,b):xs) n) = CVar i n | ||
540 | 559 | ||
541 | mkidn :: Show a => a -> NodeInfo -> Ident | 560 | mkidn :: Show a => a -> NodeInfo -> Ident |
542 | mkidn num n = C.Ident ("a"++show num) 0 n | 561 | mkidn num n = C.Ident ("a"++show num) 0 n |