packages feed

language-c99-simple 0.1.1 → 0.1.2

raw patch · 3 files changed

+34/−16 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Language.C99.Simple.Translate: transstorespec :: StorageSpec -> StorageClassSpec
- Language.C99.Simple.Translate: getdeclnspecs :: Type -> DeclnSpecs
+ Language.C99.Simple.Translate: getdeclnspecs :: Maybe StorageSpec -> Type -> DeclnSpecs

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for language-c99-simple +## 0.1.2 -- 2019-05-12++* Added support for storagespec.+ ## 0.1.1  -- 2019-04-01  * Implemented `transtypename`, used in typecasts.
language-c99-simple.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                language-c99-simple-version:             0.1.1+version:             0.1.2 synopsis:            C-like AST to simplify writing C99 programs. description:   This package is a wrapper on top of 'language-c99'. It provides a simpler
src/Language/C99/Simple/Translate.hs view
@@ -21,7 +21,7 @@ transfundef :: FunDef -> C.FunDef transfundef (FunDef ty name params decln ss) =   C.FunDef dspecs declr Nothing body where-    dspecs   = getdeclnspecs ty+    dspecs   = getdeclnspecs Nothing ty     body     = compound decln ss     declr    = execState (getdeclr ty) fundeclr     fundeclr = C.Declr Nothing (fundirectdeclr name params)@@ -29,29 +29,29 @@ transdecln :: Decln -> C.Decln transdecln decln = case decln of   FunDecln storespec ty name params -> C.Decln dspecs dlist where-    dspecs     = getdeclnspecs ty+    dspecs     = getdeclnspecs storespec ty     dlist      = Just $ C.InitDeclrBase $ C.InitDeclr declr     declr      = execState (getdeclr ty) fundeclr     fundeclr   = C.Declr Nothing (fundirectdeclr name params)    VarDecln storespec ty name init -> C.Decln dspecs dlist where-    dspecs = getdeclnspecs ty+    dspecs = getdeclnspecs storespec ty     dlist  = Just $ case init of       Nothing  -> C.InitDeclrBase $ C.InitDeclr      declr       Just val -> C.InitDeclrBase $ C.InitDeclrInitr declr (transinit val)     declr  = execState (getdeclr ty) (identdeclr name)    TypeDecln ty -> C.Decln dspecs Nothing where-    dspecs = getdeclnspecs ty+    dspecs = getdeclnspecs Nothing ty  transparamdecln :: Param -> C.ParamDecln transparamdecln (Param ty name) = C.ParamDecln dspecs declr where-  dspecs = getdeclnspecs ty+  dspecs = getdeclnspecs Nothing ty   declr  = execState (getdeclr ty) (identdeclr name)  transparam :: Param -> C.Decln transparam (Param ty name) = C.Decln dspecs dlist where-  dspecs = getdeclnspecs ty+  dspecs = getdeclnspecs Nothing ty   dlist  = Just $ C.InitDeclrBase $ C.InitDeclr declr   declr  = execState (getdeclr ty) (identdeclr name) @@ -84,16 +84,30 @@   Volatile ty' -> getdeclr ty'  -getdeclnspecs :: Type -> C.DeclnSpecs-getdeclnspecs ty = case ty of-  Type     ty'   -> getdeclnspecs ty'-  TypeSpec ty'   -> foldtypespecs $ spec2spec ty'-  Ptr      ty'   -> getdeclnspecs (snd $ gettypequals ty')-  Array    ty' _ -> getdeclnspecs ty'-  Const    ty'   -> C.DeclnSpecsQual C.QConst    (Just $ getdeclnspecs ty')-  Restrict ty'   -> C.DeclnSpecsQual C.QRestrict (Just $ getdeclnspecs ty')-  Volatile ty'   -> C.DeclnSpecsQual C.QVolatile (Just $ getdeclnspecs ty')+getdeclnspecs :: Maybe StorageSpec -> Type -> C.DeclnSpecs+getdeclnspecs storespec ty = dspecs where+  dspecs = case storespec of+    Nothing   -> tyspec+    Just spec -> C.DeclnSpecsStorage (transstorespec spec) (Just tyspec) +  tyspec = case ty of+    Type     ty'   -> rec ty'+    TypeSpec ty'   -> foldtypespecs $ spec2spec ty'+    Ptr      ty'   -> rec (snd $ gettypequals ty')+    Array    ty' _ -> rec ty'+    Const    ty'   -> C.DeclnSpecsQual C.QConst    (Just $ rec ty')+    Restrict ty'   -> C.DeclnSpecsQual C.QRestrict (Just $ rec ty')+    Volatile ty'   -> C.DeclnSpecsQual C.QVolatile (Just $ rec ty')++  rec = getdeclnspecs Nothing++transstorespec :: StorageSpec -> C.StorageClassSpec+transstorespec spec = case spec of+  Typedef  -> C.STypedef+  Extern   -> C.SExtern+  Static   -> C.SStatic+  Auto     -> C.SAuto+  Register -> C.SRegister  spec2spec :: TypeSpec -> [C.TypeSpec] spec2spec ts = case ts of