hlint: fix suggested improvements
[mate.git] / Mate / Utilities.hs
index 7002d19a9708526094ec6e6b0f9295093a20df3a..4d1cd07a5ad6a1153dddbe77e2bee0b0c8c590b5 100644 (file)
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
 module Mate.Utilities where
 
@@ -20,14 +21,31 @@ lookupMethod name cls = look (classMethods cls)
       | otherwise  = look fs
 
 buildMethodID :: Class Resolved -> Word16 -> MethodInfo
-buildMethodID cls idx = MethodInfo (ntName nt) rc (ntSignature nt) idx
-  where
-  (CMethod rc nt) = (constsPool cls) M.! idx
+buildMethodID cls idx = MethodInfo (ntName nt) rc (ntSignature nt)
+  where (rc, nt) = case constsPool cls M.! idx of
+                    (CMethod rc' nt') -> (rc', nt')
+                    (CIfaceMethod rc' nt') -> (rc', nt')
+                    _ -> error "buildMethodID: something wrong. abort."
+
+buildStaticFieldID :: Class Resolved -> Word16 -> StaticFieldInfo
+buildStaticFieldID cls idx = StaticFieldInfo rc (ntName fnt)
+  where (CField rc fnt) = constsPool cls M.! idx
+
+buildFieldOffset :: Class Resolved -> Word16 -> (B.ByteString, B.ByteString)
+buildFieldOffset cls idx = (rc, ntName fnt)
+  where (CField rc fnt) = constsPool cls M.! idx
+
+buildClassID :: Class Resolved -> Word16 -> B.ByteString
+buildClassID cls idx = cl
+  where (CClass cl) = constsPool cls M.! idx
 
 methodGetArgsCount :: Class Resolved -> Word16 -> Word32
 methodGetArgsCount cls idx = fromIntegral $ length args
   where
-  (CMethod _ nt) = (constsPool cls) M.! idx
+  nt = case constsPool cls M.! idx of
+    (CMethod _ nt') -> nt'
+    (CIfaceMethod _ nt') -> nt'
+    _ -> error "methodGetArgsCount: something wrong. abort."
   (MethodSignature args _) = ntSignature nt
 
 -- TODO(bernhard): Extend it to more than just int, and provide typeinformation
@@ -35,7 +53,11 @@ methodHaveReturnValue :: Class Resolved -> Word16 -> Bool
 methodHaveReturnValue cls idx = case ret of
     ReturnsVoid -> False;
     (Returns IntType) -> True;
+    (Returns (ObjectType _)) -> True;
     _ -> error "methodHaveReturnValue: todo"
   where
-  (CMethod _ nt) = (constsPool cls) M.! idx
+  nt = case constsPool cls M.! idx of
+    (CMethod _ nt') -> nt'
+    (CIfaceMethod _ nt') -> nt'
+    _ -> error "methodHaveReturnValue: something wrong. abort."
   (MethodSignature _ ret) = ntSignature nt