[project @ 1999-02-18 17:13:54 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / OccName.lhs
index cba9b4f..220bc06 100644 (file)
@@ -27,7 +27,7 @@ module OccName (
        mkSrcOccFS, mkSysOcc, mkSysOccFS, mkSrcVarOcc, mkKindOccFS,
        mkSuperDictSelOcc, mkDFunOcc, mkForeignExportOcc,
        mkDictOcc, mkWorkerOcc, mkMethodOcc, mkDefaultMethodOcc,
-       mkClassTyConOcc, mkClassDataConOcc, mkSpecOcc,
+       mkDerivedTyConOcc, mkClassTyConOcc, mkClassDataConOcc, mkSpecOcc,
        
        isTvOcc, isDataOcc, isDataSymOcc, isSymOcc,
 
@@ -366,7 +366,7 @@ Here's our convention for splitting up the interface file name space:
                        (local variables, so no name-clash worries)
 
        $f...           dict-fun identifiers (from inst decls)
-       $m...           default methods
+       $dm...          default methods
        $p...           superclass selectors
        $w...           workers
        $T...           compiler-generated tycons for dictionaries
@@ -394,16 +394,16 @@ mk_deriv occ_sp sys_prefix str = mkSysOcc occ_sp (encode sys_prefix ++ str)
 \end{code}
 
 \begin{code}
-mkDictOcc, mkWorkerOcc, mkMethodOcc, mkDefaultMethodOcc,
+mkDictOcc, mkWorkerOcc, mkDefaultMethodOcc,
           mkClassTyConOcc, mkClassDataConOcc, mkSpecOcc
    :: OccName -> OccName
 
 -- These derived variables have a prefix that no Haskell value could have
 mkWorkerOcc        = mk_simple_deriv varName  "$w"
-mkMethodOcc       = mk_simple_deriv varName  "$m"
 mkDefaultMethodOcc = mk_simple_deriv varName  "$dm"
-mkClassTyConOcc    = mk_simple_deriv tcName   ":T"     -- The : prefix makes sure it classifies
-mkClassDataConOcc  = mk_simple_deriv dataName ":D"     -- as a tycon/datacon
+mkDerivedTyConOcc  = mk_simple_deriv tcName   ":"      -- The : prefix makes sure it classifies
+mkClassTyConOcc    = mk_simple_deriv tcName   ":T"     -- as a tycon/datacon
+mkClassDataConOcc  = mk_simple_deriv dataName ":D"     --
 mkDictOcc         = mk_simple_deriv varName  "$d"
 mkSpecOcc         = mk_simple_deriv varName  "$s"
 mkForeignExportOcc = mk_simple_deriv varName  "$f"
@@ -437,6 +437,31 @@ mkDFunOcc cls_occ tycon_occ index
               | otherwise  = show index
 \end{code}
 
+We used to add a '$m' to indicate a method, but that gives rise to bad
+error messages from the type checker when we print the function name or pattern
+of an instance-decl binding.  Why? Because the binding is zapped
+to use the method name in place of the selector name.
+(See TcClassDcl.tcMethodBind)
+
+The way it is now, -ddump-xx output may look confusing, but
+you can always say -dppr-debug to get the uniques.
+
+However, we *do* have to zap the first character to be lower case,
+because overloaded constructors (blarg) generate methods too.
+And convert to VarName space
+
+e.g. a call to constructor MkFoo where
+       data (Ord a) => Foo a = MkFoo a
+
+If this is necessary, we do it by prefixing '$m'.  These 
+guys never show up in error messages.  What a hack.
+
+\begin{code}
+mkMethodOcc :: OccName -> OccName
+mkMethodOcc occ@(OccName VarName fs) = occ
+mkMethodOcc occ                             = mk_simple_deriv varName "$m" occ
+\end{code}
+
 
 %************************************************************************
 %*                                                                     *
@@ -550,6 +575,7 @@ encode cs = case maybe_tuple cs of
 maybe_tuple ('(' : cs) = check_tuple 0 cs
 maybe_tuple other      = Nothing
 
+check_tuple :: Int -> String -> Maybe Int
 check_tuple n (',' : cs) = check_tuple (n+1) cs
 check_tuple n ")"       = Just n
 check_tuple n other      = Nothing
@@ -594,6 +620,8 @@ encode_ch '\'' = "zq"
 encode_ch '\\' = "zr"
 encode_ch '/'  = "zs"
 encode_ch '*'  = "zt"
+encode_ch '^'  = "zu"
+encode_ch '%'  = "zv"
 encode_ch c    = ['z', 'x', intToDigit hi, intToDigit lo]
               where
                 (hi,lo) = ord c `quotRem` 16
@@ -636,6 +664,8 @@ decode_escape ('q' : rest) = '\'' : decode rest
 decode_escape ('r' : rest) = '\\' : decode rest
 decode_escape ('s' : rest) = '/' : decode rest
 decode_escape ('t' : rest) = '*' : decode rest
+decode_escape ('u' : rest) = '^' : decode rest
+decode_escape ('v' : rest) = '%' : decode rest
 decode_escape ('x' : d1 : d2 : rest) = chr (digitToInt d1 * 16 + digitToInt d2)  : decode rest
 
 -- Tuples are coded as Z23T