@@ -6,8 +6,9 @@ import Data.Binary
6import Data.List (intercalate)
6import Data.List (intercalate)
7import qualified Data.Map as Map
7import qualified Data.Map as Map
8import Control.Applicative ((<$>), (<*>))
8import Control.Applicative ((<$>), (<*>))
9+import Control.Arrow (second)
10−import SourceSyntax.Expression
11+import SourceSyntax.Expression (LExpr)
11import SourceSyntax.Declaration
12import SourceSyntax.Declaration
12import SourceSyntax.Type
13import SourceSyntax.Type
13import System.FilePath (joinPath)
14import System.FilePath (joinPath)
@@ -46,4 +47,35 @@ data ModuleInterface = ModuleInterface {
47instance Binary ModuleInterface where
48instance Binary ModuleInterface where
48 put modul = put (iTypes modul) >> put (iAdts modul)
49 put modul = put (iTypes modul) >> put (iAdts modul)
49− get = ModuleInterface <$> get <*> get
50+ get = ModuleInterface <$> get <*> get
53+canonicalize :: String -> ImportMethod -> ModuleInterface -> ModuleInterface
54+canonicalize prefix importMethod interface =
55+ let addPrefix name = prefix ++ "." ++ name
59+ As name -> (tipe, name ++ "." ++ tipe)
60+ Hiding vs -> (tipe, if tipe `elem` vs then addPrefix tipe else tipe)
61+ Importing vs -> (tipe, if tipe `elem` vs then tipe else addPrefix tipe)
62+ newNames = Map.fromList . map newName $ iAdts interface
64+ rename name = Map.findWithDefault name name newNames
66+ renameADT (name, tvars, ctors) =
67+ (rename name, tvars, map (second (map (renameType rename))) ctors)
69+ iTypes = Map.map (renameType rename) (iTypes interface),
70+ iAdts = map renameADT (iAdts interface)
73+renameType :: (String -> String) -> Type -> Type
74+renameType find tipe =
75+ let rnm = renameType find in
77+ Lambda a b -> Lambda (rnm a) (rnm b)
79+ Data name ts -> Data (find name) (map rnm ts)
80+ EmptyRecord -> EmptyRecord
81+ Record fields ext -> Record (Map.map (map rnm) fields) (rnm ext)