-stateAndPtrPrimTyCon
- = pcNonRecDataTyCon stateAndPtrPrimTyConKey pREL_ST SLIT("StateAndPtr#")
- alpha_beta_tyvars [stateAndPtrPrimDataCon]
-stateAndPtrPrimDataCon
- = pcDataCon stateAndPtrPrimDataConKey pREL_ST SLIT("StateAndPtr#")
- alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
- stateAndPtrPrimTyCon
-
-stateAndCharPrimTyCon
- = pcNonRecDataTyCon stateAndCharPrimTyConKey pREL_ST SLIT("StateAndChar#")
- alpha_tyvar [stateAndCharPrimDataCon]
-stateAndCharPrimDataCon
- = pcDataCon stateAndCharPrimDataConKey pREL_ST SLIT("StateAndChar#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
- stateAndCharPrimTyCon
-
-stateAndIntPrimTyCon
- = pcNonRecDataTyCon stateAndIntPrimTyConKey pREL_ST SLIT("StateAndInt#")
- alpha_tyvar [stateAndIntPrimDataCon]
-stateAndIntPrimDataCon
- = pcDataCon stateAndIntPrimDataConKey pREL_ST SLIT("StateAndInt#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
- stateAndIntPrimTyCon
-
-stateAndWordPrimTyCon
- = pcNonRecDataTyCon stateAndWordPrimTyConKey pREL_ST SLIT("StateAndWord#")
- alpha_tyvar [stateAndWordPrimDataCon]
-stateAndWordPrimDataCon
- = pcDataCon stateAndWordPrimDataConKey pREL_ST SLIT("StateAndWord#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
- stateAndWordPrimTyCon
-
-stateAndAddrPrimTyCon
- = pcNonRecDataTyCon stateAndAddrPrimTyConKey pREL_ST SLIT("StateAndAddr#")
- alpha_tyvar [stateAndAddrPrimDataCon]
-stateAndAddrPrimDataCon
- = pcDataCon stateAndAddrPrimDataConKey pREL_ST SLIT("StateAndAddr#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
- stateAndAddrPrimTyCon
-
-stateAndStablePtrPrimTyCon
- = pcNonRecDataTyCon stateAndStablePtrPrimTyConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
- alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
-stateAndStablePtrPrimDataCon
- = pcDataCon stateAndStablePtrPrimDataConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
- alpha_beta_tyvars []
- [mkStatePrimTy alphaTy, mkTyConApp stablePtrPrimTyCon [betaTy]]
- stateAndStablePtrPrimTyCon
-
-stateAndForeignObjPrimTyCon
- = pcNonRecDataTyCon stateAndForeignObjPrimTyConKey pREL_FOREIGN SLIT("StateAndForeignObj#")
- alpha_tyvar [stateAndForeignObjPrimDataCon]
-stateAndForeignObjPrimDataCon
- = pcDataCon stateAndForeignObjPrimDataConKey pREL_FOREIGN SLIT("StateAndForeignObj#")
- alpha_tyvar []
- [mkStatePrimTy alphaTy, mkTyConTy foreignObjPrimTyCon]
- stateAndForeignObjPrimTyCon
-
-stateAndFloatPrimTyCon
- = pcNonRecDataTyCon stateAndFloatPrimTyConKey pREL_ST SLIT("StateAndFloat#")
- alpha_tyvar [stateAndFloatPrimDataCon]
-stateAndFloatPrimDataCon
- = pcDataCon stateAndFloatPrimDataConKey pREL_ST SLIT("StateAndFloat#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
- stateAndFloatPrimTyCon
-
-stateAndDoublePrimTyCon
- = pcNonRecDataTyCon stateAndDoublePrimTyConKey pREL_ST SLIT("StateAndDouble#")
- alpha_tyvar [stateAndDoublePrimDataCon]
-stateAndDoublePrimDataCon
- = pcDataCon stateAndDoublePrimDataConKey pREL_ST SLIT("StateAndDouble#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
- stateAndDoublePrimTyCon
+isFFIArgumentTy :: DynFlags -> Bool -> Type -> Bool
+-- Checks for valid argument type for a 'foreign import'
+isFFIArgumentTy dflags is_safe ty
+ = checkRepTyCon (legalOutgoingTyCon dflags is_safe) ty
+
+isFFIExternalTy :: Type -> Bool
+-- Types that are allowed as arguments of a 'foreign export'
+isFFIExternalTy ty = checkRepTyCon legalFEArgTyCon ty
+
+isFFIImportResultTy :: DynFlags -> Type -> Bool
+isFFIImportResultTy dflags ty
+ = checkRepTyCon (legalFIResultTyCon dflags) ty
+
+isFFIExportResultTy :: Type -> Bool
+isFFIExportResultTy ty = checkRepTyCon legalFEResultTyCon ty
+
+isFFIDynArgumentTy :: Type -> Bool
+-- The argument type of a foreign import dynamic must be Ptr, Addr,
+-- or a newtype of either.
+isFFIDynArgumentTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == addrTyCon)
+
+isFFIDynResultTy :: Type -> Bool
+-- The result type of a foreign export dynamic must be Ptr, Addr,
+-- or a newtype of either.
+isFFIDynResultTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == addrTyCon)
+
+isFFILabelTy :: Type -> Bool
+-- The type of a foreign label must be Ptr, Addr,
+-- or a newtype of either.
+isFFILabelTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == addrTyCon)
+
+checkRepTyCon :: (TyCon -> Bool) -> Type -> Bool
+ -- look through newtypes
+checkRepTyCon check_tc ty = checkTyCon check_tc (repType ty)
+
+checkTyCon :: (TyCon -> Bool) -> Type -> Bool
+checkTyCon check_tc ty = case splitTyConApp_maybe ty of
+ Just (tycon, _) -> check_tc tycon
+ Nothing -> False
+
+isTyCon :: Unique -> Type -> Bool
+isTyCon uniq ty = checkTyCon (\tc -> uniq == getUnique tc) ty