hlint: fix suggested improvements
[mate.git] / Mate / BasicBlocks.hs
index bf34eee25e57d1e3c6ff138d0b30962f0e8178b8..3c0b93cfef82b9380aedce1f04aedeceaae0bdf1 100644 (file)
@@ -89,8 +89,8 @@ test_04 = testInstance "./tests/Fac.class" "fac"
 parseMethod :: Class Resolved -> B.ByteString -> IO (Maybe MapBB)
 parseMethod cls method = do
                      let maybe_bb = testCFG $ lookupMethod method cls
-                     let msig = methodSignature $ (classMethods cls) !! 1
-                     printfBb "BB: analysing \"%s\"\n" $ toString (method `B.append` ": " `B.append` (encode msig))
+                     let msig = methodSignature $ classMethods cls !! 1
+                     printfBb "BB: analysing \"%s\"\n" $ toString (method `B.append` ": " `B.append` encode msig)
 #ifdef DBG_BB
                      printMapBB maybe_bb
 #endif
@@ -124,7 +124,7 @@ markBackwardTargets :: [OffIns] -> [OffIns]
 markBackwardTargets [] = []
 markBackwardTargets (x:[]) = [x]
 markBackwardTargets insns@(x@((x_off,x_bbend),x_ins):y@((y_off,_),_):xs) =
-  (x_new):(markBackwardTargets (y:xs))
+  x_new:markBackwardTargets (y:xs)
   where
   x_new = if isTarget then checkX y_off else x
   checkX w16 = case x_bbend of
@@ -133,8 +133,8 @@ markBackwardTargets insns@(x@((x_off,x_bbend),x_ins):y@((y_off,_),_):xs) =
 
   -- look through all remaining insns in the stream if there is a jmp to `y'
   isTarget = case find cmpOffset insns of Just _ -> True; Nothing -> False
-  cmpOffset ((_,(Just (OneTarget w16))),_) = w16 == y_off
-  cmpOffset ((_,(Just (TwoTarget _ w16))),_) = w16 == y_off
+  cmpOffset ((_,Just (OneTarget w16)),_) = w16 == y_off
+  cmpOffset ((_,Just (TwoTarget _ w16)),_) = w16 == y_off
   cmpOffset _ = False
 
 
@@ -150,27 +150,27 @@ buildCFG' hmap (((off, entry), _):xs) insns = buildCFG' (insertlist entryi hmap)
     value = parseBasicBlock y insns
 
   entryi :: [BlockID]
-  entryi = (if off == 0 then [0] else []) ++ -- also consider the entrypoint
-        case entry of
-        Just (TwoTarget t1 t2) -> [t1, t2]
-        Just (OneTarget t) -> [t]
-        Just (FallThrough t) -> [t]
-        Just (Return) -> []
-        Nothing -> []
+  entryi = if off == 0 then 0:ys else ys -- also consider the entrypoint
+    where ys = case entry of
+              Just (TwoTarget t1 t2) -> [t1, t2]
+              Just (OneTarget t) -> [t]
+              Just (FallThrough t) -> [t]
+              Just Return -> []
+              Nothing -> []
 
 
 parseBasicBlock :: Int -> [OffIns] -> BasicBlock
 parseBasicBlock i insns = BasicBlock insonly endblock
   where
   startlist = dropWhile (\((x,_),_) -> x < i) insns
-  (Just ((_,(Just endblock)),_), is) = takeWhilePlusOne validins startlist
+  (Just ((_, Just endblock),_), is) = takeWhilePlusOne validins startlist
   insonly = snd $ unzip is
 
   -- also take last (non-matched) element and return it
   takeWhilePlusOne :: (a -> Bool) -> [a] -> (Maybe a,[a])
   takeWhilePlusOne _ [] = (Nothing,[])
   takeWhilePlusOne p (x:xs)
-    | p x       =  let (lastins, list) = takeWhilePlusOne p xs in (lastins, (x:list))
+    | p x       =  let (lastins, list) = takeWhilePlusOne p xs in (lastins, x:list)
     | otherwise =  (Just x,[x])
 
   validins :: ((Int, Maybe BBEnd), Instruction) -> Bool
@@ -181,11 +181,11 @@ calculateInstructionOffset :: [Instruction] -> [OffIns]
 calculateInstructionOffset = cio' (0, Nothing)
   where
   newoffset :: Instruction -> Int -> Offset
-  newoffset x off = (off + (fromIntegral $ B.length $ encodeInstructions [x]), Nothing)
+  newoffset x off = (off + fromIntegral (B.length $ encodeInstructions [x]), Nothing)
 
   addW16Signed :: Int -> Word16 -> Int
-  addW16Signed i w16 = i + (fromIntegral s16)
-    where s16 = (fromIntegral w16) :: Int16
+  addW16Signed i w16 = i + fromIntegral s16
+    where s16 = fromIntegral w16 :: Int16
 
   cio' :: Offset -> [Instruction] -> [OffIns]
   cio' _ [] = []
@@ -201,6 +201,6 @@ calculateInstructionOffset = cio' (0, Nothing)
       _ -> ((off, Nothing), x):next
     where
     notarget = ((off, Just Return), x):next
-    onetarget w16 = ((off, Just $ OneTarget (off `addW16Signed` w16)), x):next
+    onetarget w16 = ((off, Just $ OneTarget (off `addW16Signed` w16)), x):next
     twotargets w16 = ((off, Just $ TwoTarget (off + 3) (off `addW16Signed` w16)), x):next
     next = cio' (newoffset x off) xs