on master help sign in
Fix error in Java name mangling

The name mangler was creating invalid names, which were truncated, leading to collisions for test038. Additionally, more potential collisions are fixed by padding digit codes to a common length, so that identifiers containing numbers don't clash with different-length character codes.

commitb5e9afe1e1375fcf91db549dcdab8e176fd77adf authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateWed 29 Jan 2014, 18:11 (13 years ago) parent4c2a230
1 file changed+4−1
src/IRTS/Java/Mangling.hs+4−1
src/IRTS/Java/Mangling.hs+4−1
@@ -88,7 +88,8 @@ mangleWithPrefix prefix (UN name) =
8888 | x == ' ' = "_Space" ++ cleanNonLetter xs
8989 | x == ',' = "_Comma" ++ cleanNonLetter xs
9090 | x == '_' = "__" ++ cleanNonLetter xs
91− | not (isAlphaNum x) = "_" ++ (show $ ord x) ++ xs
91+ -- 10 digits is the most possible to represent 2^32 (ie all of unicode)
92+ | not (isAlphaNum x) = "_" ++ (padToWith 10 '0' . show $ ord x) ++ cleanNonLetter xs
9293 | otherwise = x:cleanNonLetter xs
9394 cleanNonLetter [] = []
9495 cleanWs capitalize (x:xs)
@@ -96,6 +97,8 @@ mangleWithPrefix prefix (UN name) =
9697 | capitalize = (toUpper x) : (cleanWs False xs)
9798 | otherwise = x : (cleanWs False xs)
9899 cleanWs _ [] = []
100+ padToWith :: Int -> a -> [a] -> [a]
101+ padToWith n p xs = replicate (length xs - n) p ++ xs
99102mangleWithPrefix prefix s@(SN _) = mangleWithPrefix prefix (sUN (showCG s))
100103
101104mangle :: (Applicative m, MonadError String m) => Name -> m Ident