Interface.hs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. module Gidl.Interface
  2. ( module Gidl.Interface.AST
  3. , lookupInterface
  4. , insertInterface
  5. , interfaceTypes
  6. , interfaceParents
  7. ) where
  8. import Data.List (nub)
  9. import Data.Maybe (fromJust)
  10. import Gidl.Interface.AST
  11. import Gidl.Types
  12. lookupInterface :: InterfaceName -> InterfaceEnv -> Maybe Interface
  13. lookupInterface iname (InterfaceEnv ie) = lookup iname ie
  14. insertInterface :: InterfaceName -> Interface -> InterfaceEnv -> InterfaceEnv
  15. insertInterface iname i e@(InterfaceEnv ie) = case lookupInterface iname e of
  16. Nothing -> InterfaceEnv ((iname,i):ie)
  17. Just _ -> error ("insertInterface invariant broken: interface " ++ iname ++ "already exists")
  18. interfaceParents :: Interface -> [InterfaceName]
  19. interfaceParents (Interface parents _) = parents
  20. interfaceTypes :: InterfaceName -> InterfaceEnv -> TypeEnv -> [TypeName]
  21. interfaceTypes iname ie te = nub $
  22. concatMap aux ms
  23. where
  24. (Interface _ ms) = fromJust (lookupInterface iname ie)
  25. aux = typeLeaves
  26. . fromJust
  27. . (\tn -> lookupTypeName tn te)
  28. . methodTN
  29. . snd
  30. methodTN :: Method -> TypeName
  31. methodTN (AttrMethod _ tn) = tn
  32. methodTN (StreamMethod _ tn) = tn