import {-# SOURCE #-} CostCentre
-import CmdLineOpts ( opt_IgnoreIfacePragmas, opt_NoHiCheck )
+import CmdLineOpts ( opt_IgnoreIfacePragmas, opt_HiVersion, opt_NoHiCheck )
import Demand ( Demand(..) {- instance Read -} )
import UniqFM ( UniqFM, listToUFM, lookupUFM)
import BasicTypes ( NewOrData(..), IfaceFlavour(..) )
import SrcLoc ( SrcLoc, incSrcLine, srcLocFile )
import Maybes ( MaybeErr(..) )
-import ErrUtils ( ErrMsg(..) )
+import ErrUtils ( ErrMsg )
import Outputable
import Util ( nOfThem, panic )
-}
checkVersion :: Maybe Integer -> IfM ()
checkVersion mb@(Just v) s l
- | (v==0) || (v == PROJECTVERSION) || opt_NoHiCheck = Succeeded ()
+ | (v==0) || (v == fromInt opt_HiVersion) || opt_NoHiCheck = Succeeded ()
| otherwise = Failed (ifaceVersionErr mb l ([]::[IfaceToken]){-Todo-})
checkVersion mb@Nothing s l
| "hi-boot" `isSuffixOf` (_UNPK_ (srcLocFile l)) = Succeeded ()
ifaceVersionErr hi_vers l toks
= hsep [ppr l, ptext SLIT("Interface file version error;"),
- ptext SLIT("Expected"), int PROJECTVERSION,
+ ptext SLIT("Expected"), int opt_HiVersion,
ptext SLIT(" found "), pp_version]
where
pp_version =
\begin{code}
module PrefixSyn (
RdrBinding(..),
- RdrId,
RdrMatch(..),
SigConverter,
SrcFile,
import SrcLoc ( SrcLoc )
import Char ( isDigit, ord )
-type RdrId = RdrName
+
+--UNUSED: type RdrId = RdrName
type SrcLine = Int
type SrcFile = FAST_STRING
type SrcFun = RdrName
| RdrClassDecl RdrNameClassDecl
| RdrInstDecl RdrNameInstDecl
| RdrDefaultDecl RdrNameDefaultDecl
+ | RdrForeignDecl RdrNameForeignDecl
-- signatures are mysterious; we can't
-- tell if its a Sig or a ClassOpSig,
cvBinds,
cvMonoBindsAndSigs,
cvMatches,
- cvOtherDecls
+ cvOtherDecls,
+ cvForeignDecls -- HACK
+
) where
#include "HsVersions.h"
go acc (RdrClassDecl d) = ClD d : acc
go acc (RdrInstDecl d) = InstD d : acc
go acc (RdrDefaultDecl d) = DefD d : acc
+-- go acc (RdrForeignDecl d) = ForD d : acc
go acc other = acc
-- Ignore value bindings
+
+cvForeignDecls :: RdrBinding -> [RdrNameHsDecl]
+cvForeignDecls b = go [] b
+ where
+ go acc (RdrAndBindings b1 b2) = go (go acc b1) b2
+ go acc (RdrForeignDecl d) = ForD d : acc
+ go acc other = acc
+
\end{code}
RdrNameContext,
RdrNameSpecDataSig,
RdrNameDefaultDecl,
+ RdrNameForeignDecl,
RdrNameFixityDecl,
RdrNameGRHS,
RdrNameGRHSsAndBinds,
type RdrNameHsDecl = HsDecl Unused RdrName RdrNamePat
type RdrNameSpecDataSig = SpecDataSig RdrName
type RdrNameDefaultDecl = DefaultDecl RdrName
+type RdrNameForeignDecl = ForeignDecl RdrName
type RdrNameFixityDecl = FixityDecl RdrName
type RdrNameGRHS = GRHS Unused RdrName RdrNamePat
type RdrNameGRHSsAndBinds = GRHSsAndBinds Unused RdrName RdrNamePat
import RdrHsSyn
import BasicTypes ( Fixity(..), FixityDirection(..), NewOrData(..), IfaceFlavour(..) )
import PrefixToHs
+import CallConv
import CmdLineOpts ( opt_NoImplicitPrelude )
import FiniteMap ( elemFM, FiniteMap )
let
val_decl = ValD (cvBinds srcfile cvValSig binding)
+ for_decls = cvForeignDecls binding
other_decls = cvOtherDecls binding
in
returnUgn (modname,
exports
imports
fixities
- (val_decl: other_decls)
+ (for_decls ++ val_decl: other_decls)
src_loc
)
\end{code}
wlkList rdMonoType dbindts `thenUgn` \ tys ->
returnUgn (RdrDefaultDecl (DefaultDecl tys src_loc))
+ -- "foreign" declaration
+ U_fobind id ty ext_name unsafe_flag cconv imp_exp srcline ->
+ mkSrcLocUgn srcline $ \ src_loc ->
+ wlkVarId id `thenUgn` \ h_id ->
+ wlkHsType ty `thenUgn` \ h_ty ->
+ wlkExtName ext_name `thenUgn` \ h_ext_name ->
+ rdCallConv cconv `thenUgn` \ h_cconv ->
+ rdImpExp imp_exp (cvFlag unsafe_flag) `thenUgn` \ h_imp_exp ->
+ returnUgn (RdrForeignDecl (ForeignDecl h_id h_imp_exp h_ty h_ext_name h_cconv src_loc))
+
a_sig_we_hope ->
-- signature(-like) things, including user pragmas
wlk_sig_thing a_sig_we_hope
returnUgn (IEModuleContents mod)
\end{code}
+
+%************************************************************************
+%* *
+\subsection[rdExtName]{Read an external name}
+%* *
+%************************************************************************
+
+\begin{code}
+wlkExtName :: U_maybe -> UgnM ExtName
+wlkExtName (U_nothing) = returnUgn Dynamic
+wlkExtName (U_just pt)
+ = rdU_list pt `thenUgn` \ ds ->
+ wlkList rdU_hstring ds `thenUgn` \ ss ->
+ case ss of
+ [nm] -> returnUgn (ExtName nm Nothing)
+ [mod,nm] -> returnUgn (ExtName nm (Just mod))
+
+rdCallConv :: Int -> UgnM CallConv
+rdCallConv x = returnUgn x
+
+rdImpExp :: Int -> Bool -> UgnM (Maybe Bool)
+rdImpExp 0 isUnsafe = -- foreign import
+ returnUgn (Just isUnsafe)
+rdImpExp 1 _ = -- foreign export
+ returnUgn Nothing
+\end{code}