- test _ = False
-
-
-
-fieldInfo :: [CpInfo] -> Field -> FieldInfo
-fieldInfo pool (Field {..}) = FieldInfo {
- fieldAccessFlags = access2word16 fieldAccess,
- fieldNameIndex = poolIndex pool fieldName,
- fieldSignatureIndex = poolIndex pool (encode fieldSignature),
- fieldAttributesCount = fromIntegral (M.size fieldAttrs),
- fieldAttributes = map (attrInfo pool) (M.assocs fieldAttrs) }
-
-methodInfo :: [CpInfo] -> Method -> MethodInfo
-methodInfo pool (Method {..}) = MethodInfo {
- methodAccessFlags = access2word16 methodAccess,
- methodNameIndex = poolIndex pool methodName,
- methodSignatureIndex = poolIndex pool (encode methodSignature),
- methodAttributesCount = fromIntegral (M.size methodAttrs),
- methodAttributes = map (attrInfo pool) (M.assocs methodAttrs) }
+ test _ = False
+
+-- | Find index of given string in the list of constants
+poolClassIndex :: (Throws NoItemInPool e) => Pool File -> B.ByteString -> EM e Word16
+poolClassIndex list name = case findIndex checkString (M.elems list) of
+ Nothing -> throw (NoItemInPool name)
+ Just i -> case findIndex (checkClass $ fromIntegral $ i+1) (M.elems list) of
+ Nothing -> throw (NoItemInPool $ i+1)
+ Just j -> return $ fromIntegral $ j+1
+ where
+ checkString (CUTF8 s) | s == name = True
+ checkString (CUnicode s) | s == name = True
+ checkString _ = False
+
+ checkClass i (CClass x) | i == x = True
+ checkClass _ _ = False
+
+poolNTIndex list x@(NameType n t) = do
+ ni <- poolIndex list n
+ ti <- poolIndex list (byteString t)
+ case findIndex (check ni ti) (M.elems list) of
+ Nothing -> throw (NoItemInPool x)
+ Just i -> return $ fromIntegral (i+1)
+ where
+ check ni ti (CNameType n' t')
+ | (ni == n') && (ti == t') = True
+ check _ _ _ = False
+
+fieldDirect2File :: Pool File -> Field Direct -> Field File
+fieldDirect2File pool (Field {..}) = Field {
+ fieldAccessFlags = accessDirect2File fieldAccessFlags,
+ fieldName = force "field name" $ poolIndex pool fieldName,
+ fieldSignature = force "signature" $ poolIndex pool (encode fieldSignature),
+ fieldAttributesCount = fromIntegral (arsize fieldAttributes),
+ fieldAttributes = to (arlist fieldAttributes) }
+ where
+ to :: [(B.ByteString, B.ByteString)] -> Attributes File
+ to pairs = AP (map (attrInfo pool) pairs)
+
+methodDirect2File :: Pool File -> Method Direct -> Method File
+methodDirect2File pool (Method {..}) = Method {
+ methodAccessFlags = accessDirect2File methodAccessFlags,
+ methodName = force "method name" $ poolIndex pool methodName,
+ methodSignature = force "method sig" $ poolIndex pool (encode methodSignature),
+ methodAttributesCount = fromIntegral (arsize methodAttributes),
+ methodAttributes = to (arlist methodAttributes) }
+ where
+ to :: [(B.ByteString, B.ByteString)] -> Attributes File
+ to pairs = AP (map (attrInfo pool) pairs)