diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-21 02:40:58 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-21 02:40:58 -0500 |
commit | e375eb43a36062a0106d3a7d6225751cb571a77c (patch) | |
tree | 0a68f494029c742b2cc5744e8b94a2f5103f633d | |
parent | 1de5441565058259078b7d52555d551184a6e441 (diff) |
saving some work
-rw-r--r-- | c2haskell.hs | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/c2haskell.hs b/c2haskell.hs index d692558..847458c 100644 --- a/c2haskell.hs +++ b/c2haskell.hs | |||
@@ -522,6 +522,25 @@ setSetterBody name (CDeclExt (CDecl xs ys pos)) = (CFDefExt (CFunDef xs v [] (se | |||
522 | (Just y,_,_):_ -> y | 522 | (Just y,_,_):_ -> y |
523 | _ -> CDeclr Nothing [] Nothing [] pos | 523 | _ -> CDeclr Nothing [] Nothing [] pos |
524 | 524 | ||
525 | parameterIdent :: CDeclaration a -> Maybe Ident | ||
526 | parameterIdent (CDecl _ xs n) = listToMaybe $ do | ||
527 | (Just (CDeclr (Just x) _ _ _ _),_,_) <- xs | ||
528 | return x | ||
529 | |||
530 | makeParameterNames :: CDerivedDeclarator NodeInfo -> (CDerivedDeclarator NodeInfo,[CExpression NodeInfo]) | ||
531 | makeParameterNames (CFunDeclr (Right (CDecl rtyp ps n : ds, flg)) z2 z3) | ||
532 | = ( CFunDeclr (Right (CDecl rtyp qs n : ds, flg)) z2 z3 , [] ) | ||
533 | -- FIXME: Each paramter gets its own CDecl. | ||
534 | where | ||
535 | qs = zipWith mkp [0..] ps | ||
536 | mkp num (Just (CDeclr Nothing typ x ys z),a,b) = | ||
537 | (Just (CDeclr (Just $ mkidn num n) typ x ys z),a,b) | ||
538 | mkp num p = p | ||
539 | |||
540 | |||
541 | mkidn :: Show a => a -> NodeInfo -> Ident | ||
542 | mkidn num n = C.Ident ("a"++show num) 0 n | ||
543 | |||
525 | voidp :: [CDerivedDeclarator NodeInfo] | 544 | voidp :: [CDerivedDeclarator NodeInfo] |
526 | voidp = [ CFunDeclr | 545 | voidp = [ CFunDeclr |
527 | (Right ( [ CDecl | 546 | (Right ( [ CDecl |
@@ -532,14 +551,13 @@ voidp = [ CFunDeclr | |||
532 | Nothing | 551 | Nothing |
533 | [] | 552 | [] |
534 | n) | 553 | n) |
535 | , Nothing | 554 | , Nothing |
536 | , Nothing | 555 | , Nothing |
537 | ) | 556 | ) |
538 | ] | ||
539 | n | ||
540 | ] | 557 | ] |
541 | , False | 558 | n |
542 | )) | 559 | ] |
560 | , False)) | ||
543 | [] | 561 | [] |
544 | n] | 562 | n] |
545 | where n = undefNode | 563 | where n = undefNode |
@@ -561,6 +579,8 @@ setterBody name = | |||
561 | undefNode | 579 | undefNode |
562 | 580 | ||
563 | 581 | ||
582 | goMissing :: Show b => | ||
583 | Transpile [CExternalDeclaration b] -> String -> IO () | ||
564 | goMissing db cfun = do | 584 | goMissing db cfun = do |
565 | forM_ (Map.lookup cfun $ syms db) $ \si -> do | 585 | forM_ (Map.lookup cfun $ syms db) $ \si -> do |
566 | forM_ (take 1 $ symbolSource si) $ \d -> do | 586 | forM_ (take 1 $ symbolSource si) $ \d -> do |
@@ -600,6 +620,8 @@ goMissing db cfun = do | |||
600 | htyp -> putStr $ commented $ "Unsupported haskell type: " ++ HS.prettyPrint htyp | 620 | htyp -> putStr $ commented $ "Unsupported haskell type: " ++ HS.prettyPrint htyp |
601 | 621 | ||
602 | 622 | ||
623 | readComments :: (Num lin, Num col) => | ||
624 | FilePath -> IO [(lin, col, [Char])] | ||
603 | readComments fname = parseComments 1 1 <$> readFile fname | 625 | readComments fname = parseComments 1 1 <$> readFile fname |
604 | 626 | ||
605 | findCloser :: (Num a4, Num a3, Num a2, Num a1, Eq a1) => | 627 | findCloser :: (Num a4, Num a3, Num a2, Num a1, Eq a1) => |