Interface.hs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. module Gidl.Interface
  2. ( module Gidl.Interface.AST
  3. , lookupInterface
  4. , insertInterface
  5. , interfaceParents
  6. , interfaceTypes
  7. , interfaceMethods
  8. ) where
  9. import Data.List (nub)
  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 :: Interface -> InterfaceEnv -> InterfaceEnv
  15. insertInterface 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. where (Interface iname _ _) = i
  19. interfaceParents :: Interface -> [Interface]
  20. interfaceParents (Interface _ parents _) = parents
  21. interfaceTypes :: Interface -> [Type]
  22. interfaceTypes i = nub (map (methodT . snd) ms)
  23. where
  24. ms = interfaceMethods i
  25. methodT :: Method -> Type
  26. methodT (AttrMethod _ ty) = ty
  27. methodT (StreamMethod _ ty) = ty
  28. interfaceMethods :: Interface -> [(MethodName, Method)]
  29. interfaceMethods (Interface _ ps ms) = ms ++ concatMap interfaceMethods ps