X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FbasicTypes%2FOccName.lhs;h=faf7aa8988c94c6dbe4d0c10cf49823a73569fc5;hb=70b66a28aa5ef80bababb1ca239b2c69e1362147;hp=3cc7372ad628c2364131efec383defd698499226;hpb=f16228e47dbaf4c5eb710bf507b3b61bc5ad7122;p=ghc-hetmet.git diff --git a/ghc/compiler/basicTypes/OccName.lhs b/ghc/compiler/basicTypes/OccName.lhs index 3cc7372..faf7aa8 100644 --- a/ghc/compiler/basicTypes/OccName.lhs +++ b/ghc/compiler/basicTypes/OccName.lhs @@ -18,9 +18,9 @@ module OccName ( mkSuperDictSelOcc, mkDFunOcc, mkForeignExportOcc, mkDictOcc, mkIPOcc, mkWorkerOcc, mkMethodOcc, mkDefaultMethodOcc, mkDerivedTyConOcc, mkClassTyConOcc, mkClassDataConOcc, mkSpecOcc, - mkGenOcc1, mkGenOcc2, + mkGenOcc1, mkGenOcc2, mkLocalOcc, - isTvOcc, isDataOcc, isDataSymOcc, isSymOcc, isValOcc, + isTvOcc, isTcOcc, isDataOcc, isDataSymOcc, isSymOcc, isValOcc, occNameFS, occNameString, occNameUserString, occNameSpace, occNameFlavour, setOccNameSpace, @@ -40,8 +40,9 @@ module OccName ( #include "HsVersions.h" -import Char ( isDigit, isUpper, isLower, ISALPHANUM, ord, chr, digitToInt ) +import Char ( isDigit, isUpper, isLower, isAlphaNum, ord, chr, digitToInt ) import Util ( thenCmp ) +import Unique ( Unique ) import FiniteMap ( FiniteMap, emptyFM, lookupFM, addToFM, elemFM ) import Outputable import GlaExts @@ -219,11 +220,14 @@ occNameFlavour (OccName sp _) = nameSpaceString sp \end{code} \begin{code} -isTvOcc, isDataSymOcc, isSymOcc :: OccName -> Bool +isTvOcc, isDataSymOcc, isSymOcc, isTcOcc :: OccName -> Bool isTvOcc (OccName TvName _) = True isTvOcc other = False +isTcOcc (OccName TcClsName _) = True +isTcOcc other = False + isValOcc (OccName VarName _) = True isValOcc (OccName DataName _) = True isValOcc other = False @@ -258,25 +262,26 @@ Here's our convention for splitting up the interface file name space: $dm... default methods $p... superclass selectors $w... workers - $T... compiler-generated tycons for dictionaries - $D... ...ditto data cons + :T... compiler-generated tycons for dictionaries + :D... ...ditto data cons $sf.. specialised version of f in encoded form these appear as Zdfxxx etc :... keywords (export:, letrec: etc.) +--- I THINK THIS IS WRONG! This knowledge is encoded in the following functions. -@mk_deriv@ generates an @OccName@ from the one-char prefix and a string. +@mk_deriv@ generates an @OccName@ from the prefix and a string. NB: The string must already be encoded! \begin{code} mk_deriv :: NameSpace -> String -- Distinguishes one sort of derived name from another -> EncodedString -- Must be already encoded!! We don't want to encode it a - -- second time because encoding isn't itempotent + -- second time because encoding isn't idempotent -> OccName mk_deriv occ_sp sys_prefix str = mkSysOcc occ_sp (encode sys_prefix ++ str) @@ -288,15 +293,15 @@ mkDictOcc, mkIPOcc, mkWorkerOcc, mkDefaultMethodOcc, :: OccName -> OccName -- These derived variables have a prefix that no Haskell value could have -mkWorkerOcc = mk_simple_deriv varName "$w" -mkDefaultMethodOcc = mk_simple_deriv varName "$dm" -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" -mkIPOcc = mk_simple_deriv varName "$i" -mkSpecOcc = mk_simple_deriv varName "$s" -mkForeignExportOcc = mk_simple_deriv varName "$f" +mkWorkerOcc = mk_simple_deriv varName "$w" +mkDefaultMethodOcc = mk_simple_deriv varName "$dm" +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" +mkIPOcc = mk_simple_deriv varName "$i" +mkSpecOcc = mk_simple_deriv varName "$s" +mkForeignExportOcc = mk_simple_deriv varName "$f" mkGenOcc1 = mk_simple_deriv varName "$gfrom" -- Generics mkGenOcc2 = mk_simple_deriv varName "$gto" -- Generics mk_simple_deriv sp px occ = mk_deriv sp px (occNameString occ) @@ -305,9 +310,17 @@ mk_simple_deriv sp px occ = mk_deriv sp px (occNameString occ) \begin{code} mkSuperDictSelOcc :: Int -- Index of superclass, eg 3 -> OccName -- Class, eg "Ord" - -> OccName -- eg "p3Ord" + -> OccName -- eg "$p3Ord" mkSuperDictSelOcc index cls_occ = mk_deriv varName "$p" (show index ++ occNameString cls_occ) + +mkLocalOcc :: Unique -- Unique + -> OccName -- Local name (e.g. "sat") + -> OccName -- Nice unique version ("$L23sat") +mkLocalOcc uniq occ + = mk_deriv varName ("$L" ++ show uniq) (occNameString occ) + -- The Unique might print with characters + -- that need encoding (e.g. 'z'!) \end{code} @@ -426,13 +439,12 @@ The basic encoding scheme is this. foo## foozhzh foo##1 foozhzh1 fooZ fooZZ - :+ Zczp - () Z0T - (,,,,) Z4T 5-tuple - (#,,,,#) Z4H unboxed 5-tuple - (NB: the number is one different to the number of - elements. No real reason except that () is a zero-tuple, - while (,) is a 2-tuple.) + :+ ZCzp + () Z0T 0-tuple + (,,,,) Z5T 5-tuple + (# #) Z1H unboxed 1-tuple (note the space) + (#,,,,#) Z5H unboxed 5-tuple + (NB: There is no Z1T nor Z0H.) \begin{code} -- alreadyEncoded is used in ASSERTs to check for encoded @@ -446,7 +458,7 @@ alreadyEncoded s = all ok s -- in names we'd have to encode them. But we do put -- spaces in ccall "occurrences", and we don't want to -- reject them here - ok ch = ISALPHANUM ch + ok ch = isAlphaNum ch alreadyEncodedFS :: FAST_STRING -> Bool alreadyEncodedFS fs = alreadyEncoded (_UNPK_ fs) @@ -459,11 +471,13 @@ encode cs = case maybe_tuple cs of go [] = [] go (c:cs) = encode_ch c ++ go cs +maybe_tuple "(# #)" = Just("Z1H") maybe_tuple ('(' : '#' : cs) = case count_commas (0::Int) cs of - (n, '#' : ')' : cs) -> Just ('Z' : shows n "H") + (n, '#' : ')' : cs) -> Just ('Z' : shows (n+1) "H") other -> Nothing +maybe_tuple "()" = Just("Z0T") maybe_tuple ('(' : cs) = case count_commas (0::Int) cs of - (n, ')' : cs) -> Just ('Z' : shows n "T") + (n, ')' : cs) -> Just ('Z' : shows (n+1) "T") other -> Nothing maybe_tuple other = Nothing @@ -480,7 +494,9 @@ encodeFS fast_str | all unencodedChar str = fast_str unencodedChar :: Char -> Bool -- True for chars that don't need encoding unencodedChar 'Z' = False unencodedChar 'z' = False -unencodedChar c = ISALPHANUM c +unencodedChar c = c >= 'a' && c <= 'z' + || c >= 'A' && c <= 'Z' + || c >= '0' && c <= '9' encode_ch :: Char -> EncodedString encode_ch c | unencodedChar c = [c] -- Common case first @@ -563,18 +579,21 @@ decode_escape (c : rest) | isDigit c = go (digitToInt c) rest where go n (c : rest) | isDigit c = go (10*n + digitToInt c) rest - go n ('T' : rest) = '(' : replicate n ',' ++ ')' : decode rest - go n ('H' : rest) = '(' : '#' : replicate n ',' ++ '#' : ')' : decode rest + go 0 ('T' : rest) = "()" ++ (decode rest) + go n ('T' : rest) = '(' : replicate (n-1) ',' ++ ')' : decode rest + go 1 ('H' : rest) = "(# #)" ++ (decode rest) + go n ('H' : rest) = '(' : '#' : replicate (n-1) ',' ++ '#' : ')' : decode rest go n ('U' : rest) = chr n : decode rest go n other = pprPanic "decode_escape" (ppr n <+> text (c:rest)) decode_escape (c : rest) = pprTrace "decode_escape" (char c) (decode rest) +decode_escape [] = pprTrace "decode_escape" (text "empty") "" \end{code} %************************************************************************ %* * -n\subsection{Lexical categories} +\subsection{Lexical categories} %* * %************************************************************************