From dd869e9bb65298a69a7a55bcb77990cebce210a7 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Tue, 19 Mar 2019 18:55:40 -0400 Subject: sigs --- monkeypatch.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/monkeypatch.hs b/monkeypatch.hs index 58c8799..54b9f47 100644 --- a/monkeypatch.hs +++ b/monkeypatch.hs @@ -153,14 +153,18 @@ hsvar v = Var () (UnQual () (HS.Ident () v)) hspvar :: String -> HS.Pat () hspvar v = PVar () (HS.Ident () v) +cvarName :: CExpression a -> Maybe String cvarName (CVar (C.Ident n _ _) _) = Just n cvarName _ = Nothing +hsopUnit :: HS.Exp () hsopUnit = HS.Con () (Special () (UnitCon ())) +infixOp :: HS.Exp () -> String -> HS.Exp () -> HS.Exp () infixOp x op y = InfixApp () x (QVarOp () (UnQual () (Symbol () op))) y +infixFn :: HS.Exp () -> String -> HS.Exp () -> HS.Exp () infixFn x fn y = InfixApp () x (QVarOp () (UnQual () (HS.Ident () fn))) y @@ -191,6 +195,8 @@ varmap vs = Map.fromList $ map (,()) vs -- Returns a list of statements bringing variables into scope and an -- expression. +grokExpression :: CExpression a + -> Maybe ([Computation (HS.Exp ())], Computation (HS.Exp ())) grokExpression (CVar cv _) = Just $ (,) [] $ Computation { compFree = Map.singleton (identToString cv) () , compIntro = Map.empty @@ -282,6 +288,10 @@ grokExpression (C.CCall (CVar fn _) exps _) = do grokExpression _ = Nothing +grokInitialization :: Foldable t1 => + t1 (CDeclarationSpecifier t2) + -> (Maybe (CDeclarator a1), CInitializer a2) + -> Maybe (Computation (HS.Exp ())) grokInitialization _ (Just (CDeclr (Just cv0) _ _ _ _),CInitExpr exp _) = do let v = identToString cv0 (xs,x) <- grokExpression exp @@ -389,6 +399,7 @@ grokStatement (CBlockDecl (CDecl (t:ts) (v:vs) _)) = do $ foldr applyComputation (Computation Map.empty Map.empty (hsvar "go")) gs grokStatement _ = Nothing +isFunctionDecl :: CExternalDeclaration a -> Bool isFunctionDecl (CDeclExt (CDecl _ [(Just (CDeclr _ [CFunDeclr _ _ _] _ _ _),_,_)] _)) = True isFunctionDecl (CFDefExt (CFunDef _ _ _ (CCompound [] _ _) _)) = True isFunctionDecl _ = False @@ -801,11 +812,13 @@ enumCases (CDeclExt (CDecl xs _ ni)) = do CTypeSpec (CEnumType (CEnum _ (Just cs) _ _) _) <- xs return (ni,cs) +lineOfComment :: (Int, b, String) -> Int lineOfComment (l,_,s) = l + length (lines s) seekComment :: NodeInfo -> [(Int,Int,String)] -> ([(Int,Int,String)],[(Int,Int,String)]) seekComment ni cs = break (\c -> lineOfComment c>=posRow (posOfNode ni)) cs +strip :: [Char] -> [Char] strip = reverse . dropWhile isSpace . reverse . dropWhile isSpace -- cgit v1.2.3