From 15ecb2b1789854ef7c4f4cc5bceef22f85bcd223 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 27 Sep 2007 13:29:16 +0000 Subject: [PATCH] Added the -fwarn-type-defaults compiler option (for when integer literals are given a default type) and fixed the few warnings that arose from doing so --- Makefile | 1 + backends/GenerateC.hs | 3 ++- backends/GenerateCPPCSP.hs | 2 +- common/Pass.hs | 6 ------ common/TreeUtil.hs | 2 +- frontends/RainTypes.hs | 13 +++++++++---- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index b2553e6..9c48a9e 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ ghc_opts = \ -fallow-undecidable-instances \ -fwarn-unused-binds \ -fwarn-unused-imports \ + -fwarn-type-defaults \ -icommon -itransformations -ifrontends -ibackends \ $(profile_opts) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 9f66721..7bb91e8 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -307,7 +307,7 @@ cgenOverArray ops m var func tell ["_sizes[", show v, "]; "] call genVariable ops i tell ["++) {\n"] - | (v, i) <- zip [0..] indices] + | (v :: Integer, i) <- zip [0..] indices] p sequence_ [tell ["}\n"] | _ <- indices] Nothing -> return () @@ -1043,6 +1043,7 @@ cgenArrayAbbrev :: GenOps -> A.Variable -> (CGen (), A.Name -> CGen ()) cgenArrayAbbrev ops v = (tell ["&"] >> call genVariable ops v, genAASize v 0) where + genAASize :: A.Variable -> Integer -> A.Name -> CGen () genAASize (A.SubscriptedVariable _ (A.Subscript _ _) v) arg = genAASize v (arg + 1) genAASize (A.Variable _ on) arg diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 0ff9482..9429df2 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -1196,7 +1196,7 @@ cppgenOverArray ops m var func tell [".extent(", show v, "); "] call genVariable ops i tell ["++) {\n"] - | (v, i) <- zip [0..] indices] + | (v :: Integer, i) <- zip [0..] indices] p sequence_ [tell ["}\n"] | _ <- indices] Nothing -> return () diff --git a/common/Pass.hs b/common/Pass.hs index 2465284..188ee5b 100644 --- a/common/Pass.hs +++ b/common/Pass.hs @@ -93,12 +93,6 @@ debugAST p veryDebug $ pshow ps veryDebug $ "}}}" --- | Number lines in a piece of text. -numberLines :: String -> String -numberLines s - = concat $ intersperse "\n" $ [show n ++ ": " ++ s - | (n, s) <- zip [1..] (lines s)] - -- | Make a generic rule for a pass. makeGeneric :: (Data t) => (forall s. Data s => s -> PassM s) -> t -> PassM t makeGeneric top diff --git a/common/TreeUtil.hs b/common/TreeUtil.hs index 354f304..67bb704 100644 --- a/common/TreeUtil.hs +++ b/common/TreeUtil.hs @@ -128,7 +128,7 @@ checkMatch m@(Match con items) b else (gmapQi index (checkMatch f) d) --Possibly a better way? where - numIndexes = length (gmapQ (const 0) d) + numIndexes = length (gmapQ (const undefined) d) {- diff --git a/frontends/RainTypes.hs b/frontends/RainTypes.hs index 52ddc40..da786a9 100644 --- a/frontends/RainTypes.hs +++ b/frontends/RainTypes.hs @@ -70,20 +70,24 @@ constantFoldPass = everywhereASTM doExpression annnotateIntLiteralTypes :: Data t => t -> PassM t annnotateIntLiteralTypes = everywhereASTM doExpression where + --Function is separated out to easily provide the type description of Integer + powOf2 :: Integer -> Integer + powOf2 x = 2 ^ x + doExpression :: A.Expression -> PassM A.Expression doExpression (A.Literal m t (A.IntLiteral m' s)) = do t' <- if (t == A.Int64) then --it's a signed literal - (if (n >= 2^63 || n < (-(2^63))) + (if (n >= powOf2 63 || n < (-(powOf2 63))) then dieP m $ "Signed integer literal too large to fit into 64 bits: " ++ s else - if (n < (-(2^31)) || n >= 2^31) + if (n < (-(powOf2 31)) || n >= powOf2 31) then return A.Int64 else - if (n < (-(2^15)) || n >= 2^15) + if (n < (-(powOf2 15)) || n >= powOf2 15) then return A.Int32 else - if (n < (-(2^7)) || n >= 2^7) + if (n < (-(powOf2 7)) || n >= powOf2 7) then return A.Int16 else return A.Int8 ) @@ -91,6 +95,7 @@ annnotateIntLiteralTypes = everywhereASTM doExpression dieP m $ "Unsigned literals currently unsupported" return $ A.Literal m t' (A.IntLiteral m' s) where + n :: Integer n = read s doExpression e = return e