2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[ReadPrefix2]{Read parse tree built by Yacc parser}
9 #include "HsVersions.h"
14 -- used over in ReadPragmas2...
15 wlkList, rdConDecl, wlkMonoType
18 IMPORT_Trace -- ToDo: rm (debugging)
24 import HsCore -- ****** NEED TO SEE CONSTRUCTORS ******
25 import HsPragmas -- ****** NEED TO SEE CONSTRUCTORS ******
27 import IdInfo ( UnfoldingGuidance(..) )
29 import Maybes ( Maybe(..) )
38 %************************************************************************
40 \subsection[ReadPrefix-help]{Help Functions}
42 %************************************************************************
45 wlkList :: (U_VOID_STAR -> UgnM a) -> U_list -> UgnM [a]
47 wlkList wlk_it U_lnil = returnUgn []
49 wlkList wlk_it (U_lcons hd tl)
50 = wlk_it hd `thenUgn` \ hd_it ->
51 wlkList wlk_it tl `thenUgn` \ tl_it ->
52 returnUgn (hd_it : tl_it)
55 %************************************************************************
57 \subsection[rdModule]{@rdModule@: reads in a Haskell module}
59 %************************************************************************
63 (FAST_STRING, -- this module's name
64 (FAST_STRING -> Bool, -- a function to chk if <x> is in the export list
65 FAST_STRING -> Bool), -- a function to chk if <M> is among the M..
66 -- ("dotdot") modules in the export list.
67 ProtoNameModule) -- the main goods
70 = _ccall_ hspmain `thenMn` \ pt -> -- call the Yacc parser!
72 srcfile = _packCString ``input_filename'' -- What A Great Hack! (TM)
76 rdU_tree pt `thenUgn` \ (U_hmodule name himplist hexplist hmodlist srcline) ->
77 rdFixities `thenUgn` \ fixities ->
78 wlkBinding hmodlist `thenUgn` \ binding ->
79 wlkList rdImportedInterface himplist `thenUgn` \ imports ->
80 wlkList rdEntity hexplist `thenUgn` \ export_list->
81 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
83 case sepDeclsForTopBinds binding of {
84 (tydecls, tysigs, classdecls, instdecls, instsigs, defaultdecls, binds) ->
85 -- ToDo: bad for laziness??
89 mk_export_list_chker export_list,
97 (cvInstDecls True name name instdecls) -- True indicates not imported
100 (cvSepdBinds srcfile cvValSig binds)
105 mk_export_list_chker exp_list
106 = case (getIEStrings exp_list) of { (entity_info, dotdot_modules) ->
107 ( \ n -> n `elemFM` entity_info,
108 \ n -> n `elemFM` dotdot_modules )
112 Convert fixities table:
114 rdFixities :: UgnM [ProtoNameFixityDecl]
117 = ioToUgnM (_ccall_ nfixes) `thenUgn` \ num_fixities@(I# _) ->
124 = ioToUgnM (_ccall_ fixtype i) `thenUgn` \ fix_ty@(A# _) ->
125 if fix_ty == ``NULL'' then
128 ioToUgnM (_ccall_ fixop i) `thenUgn` \ fix_op@(A# _) ->
129 ioToUgnM (_ccall_ precedence i) `thenUgn` \ precedence@(I# _) ->
131 op = Unk (_packCString fix_op)
134 = _UNPK_ (_packCString fix_ty)
137 = case associativity of
138 "infix" -> InfixN op precedence
139 "infixl" -> InfixL op precedence
140 "infixr" -> InfixR op precedence
142 rd (i+1) (new_fix : acc)
147 %************************************************************************
149 \subsection[wlkExprOrPat]{@wlkExpr@ and @wlkPat@}
151 %************************************************************************
154 rdExpr :: ParseTree -> UgnM ProtoNameExpr
155 rdPat :: ParseTree -> UgnM ProtoNamePat
157 rdExpr pt = rdU_tree pt `thenUgn` \ tree -> wlkExpr tree
158 rdPat pt = rdU_tree pt `thenUgn` \ tree -> wlkPat tree
160 wlkExpr :: U_tree -> UgnM ProtoNameExpr
161 wlkPat :: U_tree -> UgnM ProtoNamePat
165 U_par expr -> -- parenthesised expr
168 U_lsection lsexp op -> -- left section
169 wlkExpr lsexp `thenUgn` \ expr ->
170 returnUgn (SectionL expr (Var op))
172 U_rsection op rsexp -> -- right section
173 wlkExpr rsexp `thenUgn` \ expr ->
174 returnUgn (SectionR (Var op) expr)
176 U_ccall fun flavor ccargs -> -- ccall/casm
177 wlkList rdExpr ccargs `thenUgn` \ args ->
181 returnUgn (CCall fun args
182 (tag == 'p' || tag == 'P') -- may invoke GC
183 (tag == 'N' || tag == 'P') -- really a "casm"
184 (panic "CCall:result_ty"))
186 U_scc label sccexp -> -- scc (set-cost-centre) expression
187 wlkExpr sccexp `thenUgn` \ expr ->
188 returnUgn (SCC label expr)
190 U_lambda lampats lamexpr srcline -> -- lambda expression
191 wlkList rdPat lampats `thenUgn` \ pats ->
192 wlkExpr lamexpr `thenUgn` \ body ->
193 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
196 (GRHSMatch (GRHSsAndBindsIn
197 [OtherwiseGRHS body src_loc]
202 U_casee caseexpr casebody -> -- case expression
203 wlkExpr caseexpr `thenUgn` \ expr ->
204 wlkList rdMatch casebody `thenUgn` \ mats ->
205 getSrcFileUgn `thenUgn` \ sf ->
207 matches = cvMatches sf True mats
209 returnUgn (Case expr matches)
211 U_ife ifpred ifthen ifelse -> -- if expression
212 wlkExpr ifpred `thenUgn` \ e1 ->
213 wlkExpr ifthen `thenUgn` \ e2 ->
214 wlkExpr ifelse `thenUgn` \ e3 ->
215 returnUgn (If e1 e2 e3)
217 U_let letvdeflist letvexpr -> -- let expression
218 wlkBinding letvdeflist `thenUgn` \ binding ->
219 wlkExpr letvexpr `thenUgn` \ expr ->
220 getSrcFileUgn `thenUgn` \ sf ->
222 binds = cvBinds sf cvValSig binding
224 returnUgn (Let binds expr)
226 U_comprh cexp cquals -> -- list comprehension
227 wlkExpr cexp `thenUgn` \ expr ->
228 wlkList rd_qual cquals `thenUgn` \ quals ->
229 returnUgn (ListComp expr quals)
232 = rdU_tree pt `thenUgn` \ qual ->
237 U_par expr -> wlk_qual expr -- overkill? (ToDo?)
240 wlkPat qpat `thenUgn` \ pat ->
241 wlkExpr qexp `thenUgn` \ expr ->
242 returnUgn (GeneratorQual pat expr)
245 wlkExpr gexp `thenUgn` \ expr ->
246 returnUgn (FilterQual expr)
248 U_eenum efrom estep eto -> -- arithmetic sequence
249 wlkExpr efrom `thenUgn` \ e1 ->
250 wlkList rdExpr estep `thenUgn` \ es2 ->
251 wlkList rdExpr eto `thenUgn` \ es3 ->
252 returnUgn (cv_arith_seq e1 es2 es3)
253 where -- ToDo: use Maybe type
254 cv_arith_seq e1 [] [] = ArithSeqIn (From e1)
255 cv_arith_seq e1 [] [e3] = ArithSeqIn (FromTo e1 e3)
256 cv_arith_seq e1 [e2] [] = ArithSeqIn (FromThen e1 e2)
257 cv_arith_seq e1 [e2] [e3] = ArithSeqIn (FromThenTo e1 e2 e3)
259 U_restr restre restrt -> -- expression with type signature
260 wlkExpr restre `thenUgn` \ expr ->
261 wlkPolyType restrt `thenUgn` \ ty ->
262 returnUgn (ExprWithTySig expr ty)
264 U_negate nexp -> -- negated expression
265 wlkExpr nexp `thenUgn` \ expr ->
266 returnUgn (App (Var (Unk SLIT("negate"))) expr)
270 --------------------------------------------------------------
271 -- now the prefix items that can either be an expression or
272 -- pattern, except we know they are *expressions* here
273 -- (this code could be commoned up with the pattern version;
274 -- but it probably isn't worth it)
275 --------------------------------------------------------------
277 wlkLiteral lit `thenUgn` \ lit ->
280 U_ident n -> -- simple identifier
283 U_ap fun arg -> -- application
284 wlkExpr fun `thenUgn` \ expr1 ->
285 wlkExpr arg `thenUgn` \ expr2 ->
286 returnUgn (App expr1 expr2)
288 U_tinfixop (op, arg1, arg2) ->
289 wlkExpr arg1 `thenUgn` \ expr1 ->
290 wlkExpr arg2 `thenUgn` \ expr2 ->
291 returnUgn (OpApp expr1 (Var op) expr2)
293 U_llist llist -> -- explicit list
294 wlkList rdExpr llist `thenUgn` \ exprs ->
295 returnUgn (ExplicitList exprs)
297 U_tuple tuplelist -> -- explicit tuple
298 wlkList rdExpr tuplelist `thenUgn` \ exprs ->
299 returnUgn (ExplicitTuple exprs)
302 U_hmodule _ _ _ _ _ -> error "U_hmodule"
303 U_as _ _ -> error "U_as"
304 U_lazyp _ -> error "U_lazyp"
305 U_plusp _ _ -> error "U_plusp"
306 U_wildp -> error "U_wildp"
307 U_qual _ _ -> error "U_qual"
308 U_guard _ -> error "U_guard"
309 U_def _ -> error "U_def"
315 Patterns: just bear in mind that lists of patterns are represented as
316 a series of ``applications''.
320 U_par pat -> -- parenthesised pattern
323 U_as var as_pat -> -- "as" pattern
324 wlkPat as_pat `thenUgn` \ pat ->
325 returnUgn (AsPatIn var pat)
327 U_lazyp lazyp -> -- irrefutable ("twiddle") pattern
328 wlkPat lazyp `thenUgn` \ pat ->
329 returnUgn (LazyPatIn pat)
331 U_plusp plusn plusk -> -- n+k pattern
332 wlkPat plusn `thenUgn` \ pat ->
333 wlkLiteral plusk `thenUgn` \ lit ->
337 WildPatIn -> error "ERROR: wlkPat: GHC can't handle _+k patterns\n"
339 returnUgn (NPlusKPatIn n lit)
341 U_wildp -> returnUgn WildPatIn -- wildcard pattern
343 --------------------------------------------------------------
344 -- now the prefix items that can either be an expression or
345 -- pattern, except we know they are *patterns* here.
346 --------------------------------------------------------------
347 U_negate nexp -> -- negated pattern: negatee must be a literal
348 wlkPat nexp `thenUgn` \ lit_pat ->
350 LitPatIn lit -> returnUgn (LitPatIn (negLiteral lit))
351 _ -> panic "wlkPat: bad negated pattern!"
354 wlkLiteral lit `thenUgn` \ lit ->
355 returnUgn (LitPatIn lit)
357 U_ident n -> -- simple identifier
364 U_ap l r -> -- "application": there's a list of patterns lurking here!
365 wlk_curried_pats l `thenUgn` \ (lpat:lpats) ->
366 wlkPat r `thenUgn` \ rpat ->
370 VarPatIn x -> (x, [])
371 ConPatIn x [] -> (x, [])
372 ConOpPatIn x op y -> (op, [x, y])
373 _ -> -- sorry about the weedy msg; the parser missed this one
374 error (ppShow 100 (ppCat [ppStr "ERROR: an illegal `application' of a pattern to another one:", ppInterleave ppSP (map (ppr PprForUser) bad_app)]))
376 arg_pats = llpats ++ lpats ++ [rpat]
377 bad_app = (lpat:lpats) ++ [rpat]
379 returnUgn (ConPatIn n arg_pats)
384 wlk_curried_pats l `thenUgn` \ lpats ->
385 wlkPat r `thenUgn` \ rpat ->
386 returnUgn (lpats ++ [rpat])
388 wlkPat other `thenUgn` \ pat ->
391 U_tinfixop (op, arg1, arg2) ->
392 wlkPat arg1 `thenUgn` \ pat1 ->
393 wlkPat arg2 `thenUgn` \ pat2 ->
394 returnUgn (ConOpPatIn pat1 op pat2)
396 U_llist llist -> -- explicit list
397 wlkList rdPat llist `thenUgn` \ pats ->
398 returnUgn (ListPatIn pats)
400 U_tuple tuplelist -> -- explicit tuple
401 wlkList rdPat tuplelist `thenUgn` \ pats ->
402 returnUgn (TuplePatIn pats)
407 OLD, MISPLACED NOTE: The extra DPH syntax above is defined such that
408 to the left of a \tr{<<-} or \tr{<<=} there has to be a processor (no
409 expressions). Therefore in the pattern matching below we are taking
410 this into consideration to create the @DrawGen@ whose fields are the
411 \tr{K} patterns, pat and the exp right of the generator.
414 wlkLiteral :: U_literal -> UgnM Literal
419 U_integer s -> IntLit (as_integer s)
420 U_floatr s -> FracLit (as_rational s)
421 U_intprim s -> IntPrimLit (as_integer s)
422 U_doubleprim s -> DoublePrimLit (as_rational s)
423 U_floatprim s -> FloatPrimLit (as_rational s)
424 U_charr s -> CharLit (as_char s)
425 U_charprim s -> CharPrimLit (as_char s)
426 U_string s -> StringLit (as_string s)
427 U_stringprim s -> StringPrimLit (as_string s)
428 U_clitlit s _ -> LitLitLitIn (as_string s)
432 as_integer s = readInteger (_UNPK_ s)
433 as_rational s = _readRational (_UNPK_ s) -- non-std
437 %************************************************************************
439 \subsection{wlkBinding}
441 %************************************************************************
444 wlkBinding :: U_binding -> UgnM RdrBinding
448 U_nullbind -> -- null binding
449 returnUgn RdrNullBind
451 U_abind a b -> -- "and" binding (just glue, really)
452 wlkBinding a `thenUgn` \ binding1 ->
453 wlkBinding b `thenUgn` \ binding2 ->
454 returnUgn (RdrAndBindings binding1 binding2)
456 U_tbind tbindc tbindid tbindl tbindd srcline tpragma -> -- "data" declaration
457 wlkContext tbindc `thenUgn` \ ctxt ->
458 wlkList rdU_unkId tbindd `thenUgn` \ derivings ->
459 wlkTyConAndTyVars tbindid `thenUgn` \ (tycon, tyvars) ->
460 wlkList rdConDecl tbindl `thenUgn` \ cons ->
461 wlkDataPragma tpragma `thenUgn` \ pragma ->
462 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
463 returnUgn (RdrTyData (TyData ctxt tycon tyvars cons derivings pragma src_loc))
465 U_nbind nbindid nbindas srcline npragma -> -- "type" declaration
466 wlkTyConAndTyVars nbindid `thenUgn` \ (tycon, tyvars) ->
467 wlkMonoType nbindas `thenUgn` \ expansion ->
468 wlkTypePragma npragma `thenUgn` \ pragma ->
469 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
470 returnUgn (RdrTySynonym (TySynonym tycon tyvars expansion pragma src_loc))
472 U_fbind fbindl srcline -> -- function binding
473 wlkList rdMatch fbindl `thenUgn` \ matches ->
474 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
475 returnUgn (RdrFunctionBinding srcline matches)
477 U_pbind pbindl srcline -> -- pattern binding
478 wlkList rdMatch pbindl `thenUgn` \ matches ->
479 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
480 returnUgn (RdrPatternBinding srcline matches)
482 U_cbind cbindc cbindid cbindw srcline cpragma -> -- "class" declaration
483 wlkContext cbindc `thenUgn` \ ctxt ->
484 wlkClassAssertTy cbindid `thenUgn` \ (clas, tyvar) ->
485 wlkBinding cbindw `thenUgn` \ binding ->
486 wlkClassPragma cpragma `thenUgn` \ pragma ->
487 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
488 getSrcFileUgn `thenUgn` \ sf ->
490 (class_sigs, class_methods) = sepDeclsIntoSigsAndBinds binding
492 final_sigs = concat (map cvClassOpSig class_sigs)
493 final_methods = cvMonoBinds sf class_methods
495 returnUgn (RdrClassDecl
496 (ClassDecl ctxt clas tyvar final_sigs final_methods pragma src_loc))
498 U_ibind ibindc clas ibindi ibindw srcline ipragma -> -- "instance" declaration
499 wlkContext ibindc `thenUgn` \ ctxt ->
500 wlkMonoType ibindi `thenUgn` \ inst_ty ->
501 wlkBinding ibindw `thenUgn` \ binding ->
502 wlkInstPragma ipragma `thenUgn` \ (modname_maybe, pragma) ->
503 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
504 getSrcFileUgn `thenUgn` \ sf ->
506 (ss, bs) = sepDeclsIntoSigsAndBinds binding
507 binds = cvMonoBinds sf bs
508 uprags = concat (map cvInstDeclSig ss)
511 case modname_maybe of {
513 RdrInstDecl (\ orig_mod infor_mod here ->
514 InstDecl ctxt clas inst_ty binds here orig_mod infor_mod uprags pragma src_loc);
516 RdrInstDecl (\ _ infor_mod here ->
517 InstDecl ctxt clas inst_ty binds here orig_mod infor_mod uprags pragma src_loc)
520 U_dbind dbindts srcline -> -- "default" declaration
521 wlkList rdMonoType dbindts `thenUgn` \ tys ->
522 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
523 returnUgn (RdrDefaultDecl (DefaultDecl tys src_loc))
525 U_mbind mod mbindimp mbindren srcline ->
526 -- "import" declaration in an interface
527 wlkList rdEntity mbindimp `thenUgn` \ entities ->
528 wlkList rdRenaming mbindren `thenUgn` \ renamings ->
529 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
530 returnUgn (RdrIfaceImportDecl (IfaceImportDecl mod entities renamings src_loc))
533 -- signature(-like) things, including user pragmas
534 wlk_sig_thing a_sig_we_hope
537 ToDo: really needed as separate?
539 wlk_sig_thing (U_sbind sbindids sbindid srcline spragma) -- type signature
540 = wlkList rdU_unkId sbindids `thenUgn` \ vars ->
541 wlkPolyType sbindid `thenUgn` \ poly_ty ->
542 wlkTySigPragmas spragma `thenUgn` \ pragma ->
543 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
544 returnUgn (RdrTySig vars poly_ty pragma src_loc)
546 wlk_sig_thing (U_vspec_uprag var vspec_tys srcline) -- value specialisation user-pragma
547 = wlkList rd_ty_and_id vspec_tys `thenUgn` \ tys_and_ids ->
548 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
549 returnUgn (RdrSpecValSig [SpecSig var ty using_id src_loc
550 | (ty, using_id) <- tys_and_ids ])
552 rd_ty_and_id :: ParseTree -> UgnM (ProtoNamePolyType, Maybe ProtoName)
554 = rdU_binding pt `thenUgn` \ (U_vspec_ty_and_id vspec_ty vspec_id) ->
555 wlkPolyType vspec_ty `thenUgn` \ ty ->
556 wlkList rdU_unkId vspec_id `thenUgn` \ id_list ->
557 returnUgn(ty, case id_list of { [] -> Nothing; [x] -> Just x })
559 wlk_sig_thing (U_ispec_uprag clas ispec_ty srcline)-- instance specialisation user-pragma
560 = wlkMonoType ispec_ty `thenUgn` \ ty ->
561 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
562 returnUgn (RdrSpecInstSig (InstSpecSig clas ty src_loc))
564 wlk_sig_thing (U_inline_uprag var inline_howto srcline) -- value inlining user-pragma
565 = wlkList rdU_stringId inline_howto `thenUgn` \ howto ->
566 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
568 guidance -- ToDo: use Maybe type
571 [x] -> trace "ignoring unfold howto" }) UnfoldAlways
573 returnUgn (RdrInlineValSig (InlineSig var guidance src_loc))
575 wlk_sig_thing (U_deforest_uprag var srcline) -- "deforest me" user-pragma
576 = mkSrcLocUgn srcline `thenUgn` \ src_loc ->
577 returnUgn (RdrDeforestSig (DeforestSig var src_loc))
579 wlk_sig_thing (U_magicuf_uprag var str srcline) -- "magic" unfolding user-pragma
580 = mkSrcLocUgn srcline `thenUgn` \ src_loc ->
581 returnUgn (RdrMagicUnfoldingSig (MagicUnfoldingSig var str src_loc))
583 wlk_sig_thing (U_abstract_uprag tycon srcline) -- abstract-type-synonym user-pragma
584 = mkSrcLocUgn srcline `thenUgn` \ src_loc ->
585 returnUgn (RdrAbstractTypeSig (AbstractTypeSig tycon src_loc))
587 wlk_sig_thing (U_dspec_uprag tycon dspec_tys srcline)
588 = mkSrcLocUgn srcline `thenUgn` \ src_loc ->
589 wlkList rdMonoType dspec_tys `thenUgn` \ tys ->
591 spec_ty = MonoTyCon tycon tys
593 returnUgn (RdrSpecDataSig (SpecDataSig tycon spec_ty src_loc))
596 %************************************************************************
598 \subsection[wlkTypes]{Reading in types in various forms (and data constructors)}
600 %************************************************************************
603 rdPolyType :: ParseTree -> UgnM ProtoNamePolyType
604 rdMonoType :: ParseTree -> UgnM ProtoNameMonoType
606 rdPolyType pt = rdU_ttype pt `thenUgn` \ ttype -> wlkPolyType ttype
607 rdMonoType pt = rdU_ttype pt `thenUgn` \ ttype -> wlkMonoType ttype
609 wlkPolyType :: U_ttype -> UgnM ProtoNamePolyType
610 wlkMonoType :: U_ttype -> UgnM ProtoNameMonoType
614 U_context tcontextl tcontextt -> -- context
615 wlkContext tcontextl `thenUgn` \ ctxt ->
616 wlkMonoType tcontextt `thenUgn` \ ty ->
617 returnUgn (OverloadedTy ctxt ty)
619 U_uniforall utvs uty -> -- forall type (pragmas)
620 wlkList rdU_unkId utvs `thenUgn` \ tvs ->
621 wlkMonoType uty `thenUgn` \ ty ->
622 returnUgn (ForAllTy tvs ty)
624 other -> -- something else
625 wlkMonoType other `thenUgn` \ ty ->
626 returnUgn (UnoverloadedTy ty)
630 U_tname tycon typel -> -- tycon
631 wlkList rdMonoType typel `thenUgn` \ tys ->
632 returnUgn (MonoTyCon tycon tys)
634 U_tllist tlist -> -- list type
635 wlkMonoType tlist `thenUgn` \ ty ->
636 returnUgn (ListMonoTy ty)
639 wlkList rdPolyType ttuple `thenUgn` \ tys ->
640 returnUgn (TupleMonoTy tys)
643 wlkMonoType tfun `thenUgn` \ ty1 ->
644 wlkMonoType targ `thenUgn` \ ty2 ->
645 returnUgn (FunMonoTy ty1 ty2)
647 U_namedtvar tyvar -> -- type variable
648 returnUgn (MonoTyVar tyvar)
650 U_unidict clas t -> -- UniDict (pragmas)
651 wlkMonoType t `thenUgn` \ ty ->
652 returnUgn (MonoDict clas ty)
654 U_unityvartemplate tv_tmpl -> -- pragmas only
655 returnUgn (MonoTyVarTemplate tv_tmpl)
658 wlkMonoType ('v' : xs)
659 = wlkMonoType xs `thenUgn` \ (ty, xs1) ->
660 returnUgn (RdrExplicitPodTy ty, xs1)
663 wlkMonoType ('u' : xs)
664 = wlkList rdMonoType xs `thenUgn` \ (tys, xs1) ->
665 wlkMonoType xs1 `thenUgn` \ (ty, xs2) ->
666 returnUgn (RdrExplicitProcessorTy tys ty, xs2)
668 #endif {- Data Parallel Haskell -}
670 --wlkMonoType oops = panic ("wlkMonoType:"++oops)
674 wlkTyConAndTyVars :: U_ttype -> UgnM (ProtoName, [ProtoName])
675 wlkContext :: U_list -> UgnM ProtoNameContext
676 wlkClassAssertTy :: U_ttype -> UgnM (ProtoName, ProtoName)
678 wlkTyConAndTyVars ttype
679 = wlkMonoType ttype `thenUgn` \ (MonoTyCon tycon ty_args) ->
681 args = [ a | (MonoTyVar a) <- ty_args ]
683 returnUgn (tycon, args)
686 = wlkList rdMonoType list `thenUgn` \ tys ->
687 returnUgn (map mk_class_assertion tys)
690 = wlkMonoType xs `thenUgn` \ mono_ty ->
691 returnUgn (mk_class_assertion mono_ty)
693 mk_class_assertion :: ProtoNameMonoType -> (ProtoName, ProtoName)
695 mk_class_assertion (MonoTyCon name [(MonoTyVar tyname)]) = (name, tyname)
696 mk_class_assertion other
697 = error ("ERROR: malformed type context: "++ppShow 80 (ppr PprForUser other)++"\n")
698 -- regrettably, the parser does let some junk past
699 -- e.g., f :: Num {-nothing-} => a -> ...
703 rdConDecl :: ParseTree -> UgnM ProtoNameConDecl
706 = rdU_atype pt `thenUgn` \ (U_atc con atctypel srcline) ->
708 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
709 wlkList rdMonoType atctypel `thenUgn` \ tys ->
710 returnUgn (ConDecl con tys src_loc)
713 %************************************************************************
715 \subsection{Read a ``match''}
717 %************************************************************************
720 rdMatch :: ParseTree -> UgnM RdrMatch
723 = rdU_pbinding pt `thenUgn` \ (U_pgrhs gpat gdexprs gbind srcfun srcline) ->
725 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
726 wlkPat gpat `thenUgn` \ pat ->
727 wlkList rd_guarded gdexprs `thenUgn` \ grhss ->
728 wlkBinding gbind `thenUgn` \ binding ->
730 returnUgn (RdrMatch srcline srcfun pat grhss binding)
733 = rdU_list pt `thenUgn` \ list ->
734 wlkList rdExpr list `thenUgn` \ [g,e] ->
738 %************************************************************************
740 \subsection[wlkFixity]{Read in a fixity declaration}
742 %************************************************************************
746 wlkFixity :: ParseTree -> UgnM ProtoNameFixityDecl
749 = wlkId xs `thenUgn` \ (op, xs1) ->
750 wlkIdString xs1 `thenUgn` \ (associativity, xs2) ->
751 wlkIdString xs2 `thenUgn` \ (prec_str, xs3) ->
753 precedence = read prec_str
755 case associativity of {
756 "infix" -> returnUgn (InfixN op precedence, xs3);
757 "infixl" -> returnUgn (InfixL op precedence, xs3);
758 "infixr" -> returnUgn (InfixR op precedence, xs3)
763 %************************************************************************
765 \subsection[rdImportedInterface]{Read an imported interface}
767 %************************************************************************
770 rdImportedInterface :: ParseTree
771 -> UgnM ProtoNameImportedInterface
773 rdImportedInterface pt
774 = grab_pieces pt `thenUgn`
783 mkSrcLocUgn srcline `thenUgn` \ src_loc ->
784 wlkList rdEntity bindexp `thenUgn` \ imports ->
785 wlkList rdRenaming bindren `thenUgn` \ renamings ->
787 setSrcFileUgn bindfile ( -- OK, we're now looking inside the .hi file...
789 ) `thenUgn` \ iface_bs ->
791 case (sepDeclsForInterface iface_bs) of {
792 (tydecls,classdecls,instdecls,sigs,iimpdecls) ->
795 = MkInterface modname
797 [{-fixity decls-}] -- can't get fixity decls in here yet (ToDo)
800 (cvInstDecls False SLIT(""){-probably superceded by modname < pragmas-}
802 -- False indicates imported
803 (concat (map cvValSig sigs))
804 src_loc -- OLD: (mkSrcLoc importing_srcfile srcline)
808 ImportAll cv_iface renamings
810 expose_or_hide cv_iface imports renamings
814 = rdU_binding pt `thenUgn` \ binding ->
817 U_import a b c d e f -> (ImportSome, a, b, c, d, e, f)
818 U_hiding a b c d e f -> (ImportButHide, a, b, c, d, e, f)
823 rdRenaming :: ParseTree -> UgnM Renaming
826 = rdU_list pt `thenUgn` \ list ->
827 wlkList rdU_stringId list `thenUgn` \ [id1, id2] ->
828 returnUgn (MkRenaming id1 id2)
832 rdEntity :: ParseTree -> UgnM IE
835 = rdU_entidt pt `thenUgn` \ entity ->
837 U_entid var -> -- just a value
838 returnUgn (IEVar var)
840 U_enttype thing -> -- abstract type constructor/class
841 returnUgn (IEThingAbs thing)
843 U_enttypeall thing -> -- non-abstract type constructor/class
844 returnUgn (IEThingAll thing)
846 U_enttypecons tycon ctentcons -> -- type con w/ data cons listed
847 wlkList rdU_stringId ctentcons `thenUgn` \ cons ->
848 returnUgn (IEConWithCons tycon cons)
850 U_entclass clas centops -> -- class with ops listed
851 wlkList rdU_stringId centops `thenUgn` \ ops ->
852 returnUgn (IEClsWithOps clas ops)
854 U_entmod mod -> -- everything provided by a module
855 returnUgn (IEModuleContents mod)