Declare const ints as enums
authorunc0rr
Tue, 01 May 2012 19:29:47 +0400
changeset 6979 cd28fe36170a
parent 6978 1dc33050149d
child 6980 07a710e22846
Declare const ints as enums
tools/pas2c.hs
--- a/tools/pas2c.hs	Tue May 01 19:28:30 2012 +0400
+++ b/tools/pas2c.hs	Tue May 01 19:29:47 2012 +0400
@@ -370,8 +370,13 @@
     
 tvar2C _ (VarDeclaration isConst (ids, t) mInitExpr) = do
     t' <- liftM (((if isConst then text "const" else empty) <+>) . ) $ type2C t
+    lt <- gets lastType
     ie <- initExpr mInitExpr
-    liftM (map(\i -> t' i <+> ie)) $ mapM (id2CTyped t) ids
+    case (isConst, lt, ids, mInitExpr) of
+         (True, BTInt, [i], Just _) -> do
+             i' <- id2CTyped t i
+             return [text "enum" <> braces (i' <+> ie)]
+         _ -> liftM (map(\i -> t' i <+> ie)) $ mapM (id2CTyped t) ids
     where
     initExpr Nothing = return $ empty
     initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)