summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-03-19 18:55:40 -0400
committerJoe Crayne <joe@jerkface.net>2019-03-19 18:55:40 -0400
commitdd869e9bb65298a69a7a55bcb77990cebce210a7 (patch)
tree0807abd0d9a152f243ffb6067ffd7d2a1ae838be
parent42f56c9c4ffdc30fbc60e3c6b3a3534a4da57cc7 (diff)
sigs
-rw-r--r--monkeypatch.hs13
1 files changed, 13 insertions, 0 deletions
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))
153hspvar :: String -> HS.Pat () 153hspvar :: String -> HS.Pat ()
154hspvar v = PVar () (HS.Ident () v) 154hspvar v = PVar () (HS.Ident () v)
155 155
156cvarName :: CExpression a -> Maybe String
156cvarName (CVar (C.Ident n _ _) _) = Just n 157cvarName (CVar (C.Ident n _ _) _) = Just n
157cvarName _ = Nothing 158cvarName _ = Nothing
158 159
160hsopUnit :: HS.Exp ()
159hsopUnit = HS.Con () (Special () (UnitCon ())) 161hsopUnit = HS.Con () (Special () (UnitCon ()))
160 162
161 163
164infixOp :: HS.Exp () -> String -> HS.Exp () -> HS.Exp ()
162infixOp x op y = InfixApp () x (QVarOp () (UnQual () (Symbol () op))) y 165infixOp x op y = InfixApp () x (QVarOp () (UnQual () (Symbol () op))) y
163 166
167infixFn :: HS.Exp () -> String -> HS.Exp () -> HS.Exp ()
164infixFn x fn y = InfixApp () x (QVarOp () (UnQual () (HS.Ident () fn))) y 168infixFn x fn y = InfixApp () x (QVarOp () (UnQual () (HS.Ident () fn))) y
165 169
166 170
@@ -191,6 +195,8 @@ varmap vs = Map.fromList $ map (,()) vs
191 195
192-- Returns a list of statements bringing variables into scope and an 196-- Returns a list of statements bringing variables into scope and an
193-- expression. 197-- expression.
198grokExpression :: CExpression a
199 -> Maybe ([Computation (HS.Exp ())], Computation (HS.Exp ()))
194grokExpression (CVar cv _) = Just $ (,) [] $ Computation 200grokExpression (CVar cv _) = Just $ (,) [] $ Computation
195 { compFree = Map.singleton (identToString cv) () 201 { compFree = Map.singleton (identToString cv) ()
196 , compIntro = Map.empty 202 , compIntro = Map.empty
@@ -282,6 +288,10 @@ grokExpression (C.CCall (CVar fn _) exps _) = do
282grokExpression _ = Nothing 288grokExpression _ = Nothing
283 289
284 290
291grokInitialization :: Foldable t1 =>
292 t1 (CDeclarationSpecifier t2)
293 -> (Maybe (CDeclarator a1), CInitializer a2)
294 -> Maybe (Computation (HS.Exp ()))
285grokInitialization _ (Just (CDeclr (Just cv0) _ _ _ _),CInitExpr exp _) = do 295grokInitialization _ (Just (CDeclr (Just cv0) _ _ _ _),CInitExpr exp _) = do
286 let v = identToString cv0 296 let v = identToString cv0
287 (xs,x) <- grokExpression exp 297 (xs,x) <- grokExpression exp
@@ -389,6 +399,7 @@ grokStatement (CBlockDecl (CDecl (t:ts) (v:vs) _)) = do
389 $ foldr applyComputation (Computation Map.empty Map.empty (hsvar "go")) gs 399 $ foldr applyComputation (Computation Map.empty Map.empty (hsvar "go")) gs
390grokStatement _ = Nothing 400grokStatement _ = Nothing
391 401
402isFunctionDecl :: CExternalDeclaration a -> Bool
392isFunctionDecl (CDeclExt (CDecl _ [(Just (CDeclr _ [CFunDeclr _ _ _] _ _ _),_,_)] _)) = True 403isFunctionDecl (CDeclExt (CDecl _ [(Just (CDeclr _ [CFunDeclr _ _ _] _ _ _),_,_)] _)) = True
393isFunctionDecl (CFDefExt (CFunDef _ _ _ (CCompound [] _ _) _)) = True 404isFunctionDecl (CFDefExt (CFunDef _ _ _ (CCompound [] _ _) _)) = True
394isFunctionDecl _ = False 405isFunctionDecl _ = False
@@ -801,11 +812,13 @@ enumCases (CDeclExt (CDecl xs _ ni)) = do
801 CTypeSpec (CEnumType (CEnum _ (Just cs) _ _) _) <- xs 812 CTypeSpec (CEnumType (CEnum _ (Just cs) _ _) _) <- xs
802 return (ni,cs) 813 return (ni,cs)
803 814
815lineOfComment :: (Int, b, String) -> Int
804lineOfComment (l,_,s) = l + length (lines s) 816lineOfComment (l,_,s) = l + length (lines s)
805 817
806seekComment :: NodeInfo -> [(Int,Int,String)] -> ([(Int,Int,String)],[(Int,Int,String)]) 818seekComment :: NodeInfo -> [(Int,Int,String)] -> ([(Int,Int,String)],[(Int,Int,String)])
807seekComment ni cs = break (\c -> lineOfComment c>=posRow (posOfNode ni)) cs 819seekComment ni cs = break (\c -> lineOfComment c>=posRow (posOfNode ni)) cs
808 820
821strip :: [Char] -> [Char]
809strip = reverse . dropWhile isSpace . reverse . dropWhile isSpace 822strip = reverse . dropWhile isSpace . reverse . dropWhile isSpace
810 823
811 824