%
% (c) The Foo Project, University of Glasgow, 1999
%
% @(#) $Docid: Dec. 9th 2003 09:07 Sigbjorn Finne $
% @(#) $Contactid: sof@galois.com $
%
Higher-level marshalling code - working over Core IDL
constructs. (That's the Official Line - the Real Reason
for this module is that it avoids creating a mutual
dependency between MarshallType and MarshallDep.)
\begin{code}
\end{code}
Converting a interface method signature into its corresponding
Haskell type. This means taking into consideration the presence
of [out] parameters plus dependent arguments etc.
\begin{code}
\end{code}
@toHaskellTy@ takes care of implementing the T[] translation scheme. It differs
from @toHaskellBaseTy@ in that we're mapping to the user-level representation
of the IDL type in Haskell, not the type of its marshalled/packed representation.
\begin{code}
toHaskellTy::Bool->Type->Haskell.TypetoHaskellTyisGroundty=casetyofIntegerszs->mkIntTyszsFloatsz->mkFloatTyszCharsigned|optJNI->tyWord16|otherwise->mkCharTysignedWChar->tyWCharBool->tyBoolVoid->tyUnitOctet->tyWord8Any->tyAddrObject->tyAddrStablePtr->tyStableFunTy_resps->case(toHaskellMethodTyFalseisGroundFalseNothingpsres')of(t,Nothing)->t(t,Justc)->ctxtTyAppctwhereres'=res{resultType=removePtr(resultTyperes),resultOrigType=removePtr(resultOrigTyperes)}String_isUnique_->(ifisUniquethentyMaybeelseid)tyStringWStringisUnique_->(ifisUniquethentyMaybeelseid)tyWStringSequencet__->tyList(toHaskellTyisGroundt)Fixed{}->error"not implemented yet."Name____(Justo@Iface{})_->toHaskellTyisGroundoName_____(Justti)->casemkTyConst(haskell_typeti)oft|optCom&&isTyVart->ifisGroundthenmkTyConstvARIANTelsectxtTyApp(ctxtClassvariantClass[t])t|otherwise->tNamenm_md___->tyQConst(fmapmkHaskellTyConNamemd)(mkHaskellTyConNamenm)SafeArrayt|isGround->mkTyConstsAFEARRAY|otherwise->tyQConautoLib"SafeArray"[toHaskellTyisGroundt]ArrayVoid_->tyList(toHaskellTyisGround(PointerPtrTrueVoid))Arrayt_|optJNI->mkTyConjArray[toHaskellTyisGroundt]|otherwise->tyList(toHaskellTyisGroundt)PointerUniqueisExp(Ifacenmmd____)|optCom&&isExp->tyQConprelude"Maybe"[tyQConmdnm[mkTyConstgroundInterface]]|optCom->tyQConmdnm[iface_ptr_ty_arg]{-
Pointer Unique isExp (Iface nm mod _ attrs _ _)
| optJNI && attrs `hasAttributeWithName` "jni_iface_ty" ->
let i = tyVar "a" in
mkTyCon jObject
[ ctxtTyApp (ctxtClass (mkQualName mod nm) [mkTyCon jObject [i]]) i]
| optSubtypedInterfacePointers ->
-- Pointer to anything interface'ish is an interface pointer. Period.
tyQCon prelude "Maybe" [tyQCon mod nm [mkTyConst groundInterface]]
--tyQCon mod nm [iface_ptr_ty_arg]
| otherwise -> tyQCon prelude "Maybe" [tyQConst mod nm]
-}{- moved down
Pointer _ isExp (Iface nm mod _ attrs _ _)
| optCorba -> tyQCon mod nm [iface_ptr_ty_arg]
-- what's the IU/ID bit? Needed for processing AutoPrim.idl without
-- a hitch. ToDo: remove it.
| optHaskellToC && not (nm `elem` ["IUnknown", "IDispatch"]) -> tyQConst mod nm
| optJNI && attrs `hasAttributeWithName` "jni_iface_ty" ->
let i = tyVar "a" in
mkTyCon jObject
[ ctxtTyApp (ctxtClass (mkQualName mod nm) [mkTyCon jObject [i]]) i ]
| optSubtypedInterfacePointers -> tyQCon mod nm [iface_ptr_ty_arg]
| otherwise -> tyQConst mod nm
-}PointerUnique_(Ifacenmmd_attrs__)|optJNI&&attrs`hasAttributeWithName`"jni_iface_ty"->leti=tyVar"a"inmkTyConjObject[ctxtTyApp(ctxtClass(mkQualNamemdnm)[mkTyConjObject[i]])i]|optSubtypedInterfacePointers->-- Pointer to anything interface'ish is an interface pointer. Period.tyQConprelude"Maybe"[tyQConmdnm[mkTyConstgroundInterface]]--tyQCon md nm [iface_ptr_ty_arg]|otherwise->tyQConprelude"Maybe"[tyQConstmdnm]Pointer__(Ifacenmmd_attrs__)|optCorba->tyQConmdnm[iface_ptr_ty_arg]-- what's the IU/ID bit? Needed for processing AutoPrim.idl without-- a hitch. ToDo: remove it.|optHaskellToC&¬(nm`elem`["IUnknown","IDispatch"])->tyQConstmdnm|optJNI&&attrs`hasAttributeWithName`"jni_iface_ty"->leti=tyVar"a"inmkTyConjObject[ctxtTyApp(ctxtClass(mkQualNamemdnm)[mkTyConjObject[i]])i]|optSubtypedInterfacePointers->tyQConmdnm[iface_ptr_ty_arg]|otherwise->tyQConstmdnmPointerpt_(Name_____(Justti))|pt/=Ptr&&is_pointedti->(\x->ifpt==Unique{-&& not (isVARIANTTy x)-}thentyQConprelude"Maybe"[x]elsex)$casemkTyConst(haskell_typeti)oft|optCom&&isTyVart->ifisGroundthenmkTyConstvARIANTelsectxtTyApp(ctxtClassvariantClass[t])t|otherwise->tPointerpt_t|pt/=Ptr&&isFunTyt->toHaskellTyisGroundtPointerPtr_(Name___(Justas)__)|as`hasAttributeWithName`"foreign"->tyForeignObjPointer__t|isVoidTyt||(isConstructedTyt&&isReferenceTyt)->tyAddrPointerpt_t|pt==Ref||(optHaskellToC&&isIfaceTyt)->ifisIfaceTytthentoHaskellTyisGround(getIfaceTyt)elsetoHaskellTyisGroundt|pt==Unique->tyQConprelude"Maybe"$casetofVoid->[tyAddr]_-- optDeepMarshall -> [tyPtr (toHaskellTy isGround ty)]|optCom&&isIfaceTyt->[toHaskellTyisGround(getIfaceTyt)]|otherwise->[toHaskellTyisGroundt]-- is this right?|isVariantTyt->toHaskellTyisGroundt|otherwise->-- assumed to be a pure/raw pointertyPtr(toHaskellTyisGroundt)Structi__->tyConst'iUnionu____->tyConst'uCUnionu__->tyConst'uUnionNonu_->tyConst'uEnumi__->tyConst'iIface{}->toHaskellIfaceTyty_->error("toHaskellTy: "++showCore(ppTypety))whereiface_ptr_ty_arg=tyVar"a"tyConst'i=tyQConst(idHaskellModulei)(mkHaskellTyConName(idNamei))