c09063ea0267
authorDebian Games Team <pkg-games-devel@lists.alioth.debian.org>
Wed, 19 Oct 2022 09:40:18 +0000 (10:40 +0100)
committerGianfranco Costamagna <locutusofborg@debian.org>
Wed, 19 Oct 2022 09:40:18 +0000 (10:40 +0100)
# HG changeset patch
# User alfadur
# Date 1663732531 -10800
# Node ID c09063ea0267b1a016a3a682f6d8cb39c3f7300d
# Parent  9cd8d7748199d732cf7e5b0b245f1159bc86f0ea
fix the other 2 pred/succ conversions

Gbp-Pq: Name c09063ea0267.patch

tools/pas2c/Pas2C.hs

index ddb8a21a0eadb4b3290f7e8d2a90ff3ddf061190..7eae2023e5610602f020c0690088562376fd42ff 100644 (file)
@@ -711,8 +711,10 @@ initExpr2C' hi@(BuiltInFunction "high" [e@(InitReference e')]) = do
          a -> error $ "BuiltInFunction 'high' in initExpr: " ++ show a ++ ": " ++ show hi
 initExpr2C' (BuiltInFunction "succ" [BuiltInFunction "pred" [e]]) = initExpr2C' e
 initExpr2C' (BuiltInFunction "pred" [BuiltInFunction "succ" [e]]) = initExpr2C' e
-initExpr2C' (BuiltInFunction "succ" [e]) = liftM (\e' ->  text "(" <> e' <> text " + 1)") $ initExpr2C' e
-initExpr2C' (BuiltInFunction "pred" [e]) = liftM (\e' ->  text "(" <> e' <> text " - 1)") $ initExpr2C' e
+initExpr2C' (BuiltInFunction "succ" [e]) = 
+    liftM (parens . (<> text " + 1")) $ initExpr2C' e
+initExpr2C' (BuiltInFunction "pred" [e]) = 
+    liftM (parens . (<> text " - 1")) $ initExpr2C' e
 initExpr2C' b@(BuiltInFunction _ _) = error $ show b
 initExpr2C' (InitTypeCast t' i) = do
     e <- initExpr2C i
@@ -1089,10 +1091,10 @@ expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "high" _))) = do
          BTArray (RangeFromTo _ n) _ _ -> initExpr2C n
          _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt
 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
-expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = liftM (<> text " + 1") $ expr2C e
-expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = do
-    e'<- expr2C e
-    return $ text "(int)" <> parens e' <> text " - 1"
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = 
+    liftM (parens . (<> text " + 1")) $ expr2C e
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = 
+    liftM (parens . (<> text " - 1") . ((text "(int)") <>) . parens) $ expr2C e
 expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do
     e' <- expr2C e
     lt <- gets lastType