2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[RnExpr]{Renaming of expressions}
6 Basically dependency analysis.
8 Handles @Match@, @GRHSsAndBinds@, @HsExpr@, and @Qualifier@ datatypes. In
9 general, all of these functions return a renamed thing, and a set of
13 #include "HsVersions.h"
16 rnMatch, rnGRHSsAndBinds, rnPat,
21 IMPORT_DELOOPER(RnLoop) -- break the RnPass/RnExpr/RnBinds loops
28 import CmdLineOpts ( opt_GlasgowExts )
29 import PrelInfo ( numClass_RDR, fractionalClass_RDR, eqClass_RDR, ccallableClass_RDR,
30 creturnableClass_RDR, monadZeroClass_RDR, enumClass_RDR, ordClass_RDR,
31 ratioDataCon_RDR, negate_RDR
33 import TysPrim ( charPrimTyCon, addrPrimTyCon, intPrimTyCon,
34 floatPrimTyCon, doublePrimTyCon
36 import TyCon ( TyCon )
38 import ErrUtils ( addErrLoc, addShortErrLocLine )
41 import UniqFM ( lookupUFM{-, ufmToList ToDo:rm-} )
42 import UniqSet ( emptyUniqSet, unitUniqSet,
43 unionUniqSets, unionManyUniqSets,
46 import PprStyle ( PprStyle(..) )
47 import Util ( Ord3(..), removeDups, panic, pprPanic, assertPanic )
53 *********************************************************
57 *********************************************************
60 rnPat :: RdrNamePat -> RnMS s RenamedPat
62 rnPat WildPatIn = returnRn WildPatIn
65 = lookupBndrRn name `thenRn` \ vname ->
66 returnRn (VarPatIn vname)
69 = litOccurrence lit `thenRn_`
70 lookupImplicitOccRn eqClass_RDR `thenRn_` -- Needed to find equality on pattern
71 returnRn (LitPatIn lit)
74 = rnPat pat `thenRn` \ pat' ->
75 returnRn (LazyPatIn pat')
77 rnPat (AsPatIn name pat)
78 = rnPat pat `thenRn` \ pat' ->
79 lookupBndrRn name `thenRn` \ vname ->
80 returnRn (AsPatIn vname pat')
82 rnPat (ConPatIn con pats)
83 = lookupOccRn con `thenRn` \ con' ->
84 mapRn rnPat pats `thenRn` \ patslist ->
85 returnRn (ConPatIn con' patslist)
87 rnPat (ConOpPatIn pat1 con _ pat2)
88 = rnPat pat1 `thenRn` \ pat1' ->
89 lookupOccRn con `thenRn` \ con' ->
90 lookupFixity con `thenRn` \ fixity ->
91 rnPat pat2 `thenRn` \ pat2' ->
92 mkConOpPatRn pat1' con' fixity pat2'
94 -- Negated patters can only be literals, and they are dealt with
95 -- by negating the literal at compile time, not by using the negation
96 -- operation in Num. So we don't need to make an implicit reference
98 rnPat neg@(NegPatIn pat)
99 = checkRn (valid_neg_pat pat) (negPatErr neg)
101 rnPat pat `thenRn` \ pat' ->
102 returnRn (NegPatIn pat')
104 valid_neg_pat (LitPatIn (HsInt _)) = True
105 valid_neg_pat (LitPatIn (HsFrac _)) = True
106 valid_neg_pat _ = False
109 = rnPat pat `thenRn` \ pat' ->
110 returnRn (ParPatIn pat')
112 rnPat (NPlusKPatIn name lit)
113 = litOccurrence lit `thenRn_`
114 lookupImplicitOccRn ordClass_RDR `thenRn_`
115 lookupBndrRn name `thenRn` \ name' ->
116 returnRn (NPlusKPatIn name' lit)
118 rnPat (ListPatIn pats)
119 = addImplicitOccRn listType_name `thenRn_`
120 mapRn rnPat pats `thenRn` \ patslist ->
121 returnRn (ListPatIn patslist)
123 rnPat (TuplePatIn pats)
124 = addImplicitOccRn (tupleType_name (length pats)) `thenRn_`
125 mapRn rnPat pats `thenRn` \ patslist ->
126 returnRn (TuplePatIn patslist)
128 rnPat (RecPatIn con rpats)
129 = lookupOccRn con `thenRn` \ con' ->
130 rnRpats rpats `thenRn` \ rpats' ->
131 returnRn (RecPatIn con' rpats')
134 ************************************************************************
138 ************************************************************************
141 --rnMatch :: RdrNameMatch -> RnMS s (RenamedMatch, FreeVars)
143 rnMatch (PatMatch pat match)
144 = bindLocalsRn "pattern" binders $ \ new_binders ->
145 rnPat pat `thenRn` \ pat' ->
146 rnMatch match `thenRn` \ (match', fvMatch) ->
147 returnRn (PatMatch pat' match', fvMatch `minusNameSet` mkNameSet new_binders)
149 binders = collectPatBinders pat
151 rnMatch (GRHSMatch grhss_and_binds)
152 = rnGRHSsAndBinds grhss_and_binds `thenRn` \ (grhss_and_binds', fvs) ->
153 returnRn (GRHSMatch grhss_and_binds', fvs)
156 %************************************************************************
158 \subsubsection{Guarded right-hand sides (GRHSsAndBinds)}
160 %************************************************************************
163 --rnGRHSsAndBinds :: RdrNameGRHSsAndBinds -> RnMS s (RenamedGRHSsAndBinds, FreeVars)
165 rnGRHSsAndBinds (GRHSsAndBindsIn grhss binds)
166 = rnBinds binds $ \ binds' ->
167 rnGRHSs grhss `thenRn` \ (grhss', fvGRHS) ->
168 returnRn (GRHSsAndBindsIn grhss' binds', fvGRHS)
170 rnGRHSs [] = returnRn ([], emptyNameSet)
173 = rnGRHS grhs `thenRn` \ (grhs', fvs) ->
174 rnGRHSs grhss `thenRn` \ (grhss', fvss) ->
175 returnRn (grhs' : grhss', fvs `unionNameSets` fvss)
177 rnGRHS (GRHS guard expr locn)
178 = pushSrcLocRn locn $
179 (if not (opt_GlasgowExts || is_standard_guard guard) then
180 addWarnRn (nonStdGuardErr guard)
185 (rnStmts rnExpr guard $ \ guard' ->
186 -- This nested thing deals with scope and
187 -- the free vars of the guard, and knocking off the
188 -- free vars of the rhs that are bound by the guard
190 rnExpr expr `thenRn` \ (expr', fvse) ->
191 returnRn (GRHS guard' expr' locn, fvse))
193 rnGRHS (OtherwiseGRHS expr locn)
194 = pushSrcLocRn locn $
195 rnExpr expr `thenRn` \ (expr', fvs) ->
196 returnRn (GRHS [] expr' locn, fvs)
198 -- Standard Haskell 1.4 guards are just a single boolean
199 -- expression, rather than a list of qualifiers as in the
201 is_standard_guard [GuardStmt _ _] = True
202 is_standard_guard other = False
205 %************************************************************************
207 \subsubsection{Expressions}
209 %************************************************************************
212 --rnExprs :: [RdrNameHsExpr] -> RnMS s ([RenamedHsExpr], FreeVars)
214 rnExprs' ls [] `thenRn` \ (exprs, fvExprs) ->
215 returnRn (exprs, unionManyNameSets fvExprs)
217 rnExprs' [] acc = returnRn ([], acc)
218 rnExprs' (expr:exprs) acc
219 = rnExpr expr `thenRn` \ (expr', fvExpr) ->
220 rnExprs' exprs (fvExpr:acc) `thenRn` \ (exprs', fvExprs) ->
221 returnRn (expr':exprs', fvExprs)
224 Variables. We look up the variable and return the resulting name. The
225 interesting question is what the free-variable set should be. We
226 don't want to return imported or prelude things as free vars. So we
227 look at the Name returned from the lookup, and make it part of the
228 free-var set iff if it's a LocallyDefined Name.
232 rnExpr :: RdrNameHsExpr -> RnMS s (RenamedHsExpr, FreeVars)
235 = lookupOccRn v `thenRn` \ vname ->
236 returnRn (HsVar vname, if isLocallyDefined vname
237 then unitNameSet vname
241 = litOccurrence lit `thenRn_`
242 returnRn (HsLit lit, emptyNameSet)
245 = rnMatch match `thenRn` \ (match', fvMatch) ->
246 returnRn (HsLam match', fvMatch)
248 rnExpr (HsApp fun arg)
249 = rnExpr fun `thenRn` \ (fun',fvFun) ->
250 rnExpr arg `thenRn` \ (arg',fvArg) ->
251 returnRn (HsApp fun' arg', fvFun `unionNameSets` fvArg)
253 rnExpr (OpApp e1 op@(HsVar op_name) _ e2)
254 = rnExpr e1 `thenRn` \ (e1', fv_e1) ->
255 rnExpr e2 `thenRn` \ (e2', fv_e2) ->
256 rnExpr op `thenRn` \ (op', fv_op) ->
259 lookupFixity op_name `thenRn` \ fixity ->
260 getModeRn `thenRn` \ mode ->
262 SourceMode -> mkOpAppRn e1' op' fixity e2'
263 InterfaceMode -> returnRn (OpApp e1' op' fixity e2')
264 ) `thenRn` \ final_e ->
267 fv_e1 `unionNameSets` fv_op `unionNameSets` fv_e2)
270 = rnExpr e `thenRn` \ (e', fv_e) ->
271 lookupImplicitOccRn negate_RDR `thenRn` \ neg ->
272 getModeRn `thenRn` \ mode ->
273 mkNegAppRn mode e' (HsVar neg) `thenRn` \ final_e ->
274 returnRn (final_e, fv_e)
277 = rnExpr e `thenRn` \ (e', fvs_e) ->
278 returnRn (HsPar e', fvs_e)
280 rnExpr (SectionL expr op)
281 = rnExpr expr `thenRn` \ (expr', fvs_expr) ->
282 rnExpr op `thenRn` \ (op', fvs_op) ->
283 returnRn (SectionL expr' op', fvs_op `unionNameSets` fvs_expr)
285 rnExpr (SectionR op expr)
286 = rnExpr op `thenRn` \ (op', fvs_op) ->
287 rnExpr expr `thenRn` \ (expr', fvs_expr) ->
288 returnRn (SectionR op' expr', fvs_op `unionNameSets` fvs_expr)
290 rnExpr (CCall fun args may_gc is_casm fake_result_ty)
291 = lookupImplicitOccRn ccallableClass_RDR `thenRn_`
292 lookupImplicitOccRn creturnableClass_RDR `thenRn_`
293 rnExprs args `thenRn` \ (args', fvs_args) ->
294 returnRn (CCall fun args' may_gc is_casm fake_result_ty, fvs_args)
296 rnExpr (HsSCC label expr)
297 = rnExpr expr `thenRn` \ (expr', fvs_expr) ->
298 returnRn (HsSCC label expr', fvs_expr)
300 rnExpr (HsCase expr ms src_loc)
301 = pushSrcLocRn src_loc $
302 rnExpr expr `thenRn` \ (new_expr, e_fvs) ->
303 mapAndUnzipRn rnMatch ms `thenRn` \ (new_ms, ms_fvs) ->
304 returnRn (HsCase new_expr new_ms src_loc, unionManyNameSets (e_fvs : ms_fvs))
306 rnExpr (HsLet binds expr)
307 = rnBinds binds $ \ binds' ->
308 rnExpr expr `thenRn` \ (expr',fvExpr) ->
309 returnRn (HsLet binds' expr', fvExpr)
311 rnExpr (HsDo do_or_lc stmts src_loc)
312 = pushSrcLocRn src_loc $
313 lookupImplicitOccRn monadZeroClass_RDR `thenRn_` -- Forces Monad to come too
314 (rnStmts rnExpr stmts $ \ stmts' ->
315 returnRn (HsDo do_or_lc stmts' src_loc, emptyNameSet))
317 rnExpr (ExplicitList exps)
318 = addImplicitOccRn listType_name `thenRn_`
319 rnExprs exps `thenRn` \ (exps', fvs) ->
320 returnRn (ExplicitList exps', fvs)
322 rnExpr (ExplicitTuple exps)
323 = addImplicitOccRn (tupleType_name (length exps)) `thenRn_`
324 rnExprs exps `thenRn` \ (exps', fvExps) ->
325 returnRn (ExplicitTuple exps', fvExps)
327 rnExpr (RecordCon (HsVar con) rbinds)
328 = lookupOccRn con `thenRn` \ conname ->
329 rnRbinds "construction" rbinds `thenRn` \ (rbinds', fvRbinds) ->
330 returnRn (RecordCon (HsVar conname) rbinds', fvRbinds)
332 rnExpr (RecordUpd expr rbinds)
333 = rnExpr expr `thenRn` \ (expr', fvExpr) ->
334 rnRbinds "update" rbinds `thenRn` \ (rbinds', fvRbinds) ->
335 returnRn (RecordUpd expr' rbinds', fvExpr `unionNameSets` fvRbinds)
337 rnExpr (ExprWithTySig expr pty)
338 = rnExpr expr `thenRn` \ (expr', fvExpr) ->
339 rnHsSigType (\ sty -> text "an expression") pty `thenRn` \ pty' ->
340 returnRn (ExprWithTySig expr' pty', fvExpr)
342 rnExpr (HsIf p b1 b2 src_loc)
343 = pushSrcLocRn src_loc $
344 rnExpr p `thenRn` \ (p', fvP) ->
345 rnExpr b1 `thenRn` \ (b1', fvB1) ->
346 rnExpr b2 `thenRn` \ (b2', fvB2) ->
347 returnRn (HsIf p' b1' b2' src_loc, unionManyNameSets [fvP, fvB1, fvB2])
349 rnExpr (ArithSeqIn seq)
350 = lookupImplicitOccRn enumClass_RDR `thenRn_`
351 rn_seq seq `thenRn` \ (new_seq, fvs) ->
352 returnRn (ArithSeqIn new_seq, fvs)
355 = rnExpr expr `thenRn` \ (expr', fvExpr) ->
356 returnRn (From expr', fvExpr)
358 rn_seq (FromThen expr1 expr2)
359 = rnExpr expr1 `thenRn` \ (expr1', fvExpr1) ->
360 rnExpr expr2 `thenRn` \ (expr2', fvExpr2) ->
361 returnRn (FromThen expr1' expr2', fvExpr1 `unionNameSets` fvExpr2)
363 rn_seq (FromTo expr1 expr2)
364 = rnExpr expr1 `thenRn` \ (expr1', fvExpr1) ->
365 rnExpr expr2 `thenRn` \ (expr2', fvExpr2) ->
366 returnRn (FromTo expr1' expr2', fvExpr1 `unionNameSets` fvExpr2)
368 rn_seq (FromThenTo expr1 expr2 expr3)
369 = rnExpr expr1 `thenRn` \ (expr1', fvExpr1) ->
370 rnExpr expr2 `thenRn` \ (expr2', fvExpr2) ->
371 rnExpr expr3 `thenRn` \ (expr3', fvExpr3) ->
372 returnRn (FromThenTo expr1' expr2' expr3',
373 unionManyNameSets [fvExpr1, fvExpr2, fvExpr3])
376 %************************************************************************
378 \subsubsection{@Rbinds@s and @Rpats@s: in record expressions}
380 %************************************************************************
384 = mapRn field_dup_err dup_fields `thenRn_`
385 mapAndUnzipRn rn_rbind rbinds `thenRn` \ (rbinds', fvRbind_s) ->
386 returnRn (rbinds', unionManyNameSets fvRbind_s)
388 (_, dup_fields) = removeDups cmp [ f | (f,_,_) <- rbinds ]
390 field_dup_err dups = addErrRn (dupFieldErr str dups)
392 rn_rbind (field, expr, pun)
393 = lookupGlobalOccRn field `thenRn` \ fieldname ->
394 rnExpr expr `thenRn` \ (expr', fvExpr) ->
395 returnRn ((fieldname, expr', pun), fvExpr)
398 = mapRn field_dup_err dup_fields `thenRn_`
401 (_, dup_fields) = removeDups cmp [ f | (f,_,_) <- rpats ]
403 field_dup_err dups = addErrRn (dupFieldErr "pattern" dups)
405 rn_rpat (field, pat, pun)
406 = lookupGlobalOccRn field `thenRn` \ fieldname ->
407 rnPat pat `thenRn` \ pat' ->
408 returnRn (fieldname, pat', pun)
411 %************************************************************************
413 \subsubsection{@Stmt@s: in @do@ expressions}
415 %************************************************************************
417 Note that although some bound vars may appear in the free var set for
418 the first qual, these will eventually be removed by the caller. For
419 example, if we have @[p | r <- s, q <- r, p <- q]@, when doing
420 @[q <- r, p <- q]@, the free var set for @q <- r@ will
421 be @{r}@, and the free var set for the entire Quals will be @{r}@. This
422 @r@ will be removed only when we finally return from examining all the
426 type RnExprTy s = RdrNameHsExpr -> RnMS s (RenamedHsExpr, FreeVars)
428 rnStmts :: RnExprTy s
430 -> ([RenamedStmt] -> RnMS s (a, FreeVars))
431 -> RnMS s (a, FreeVars)
433 rnStmts rn_expr [] thing_inside
436 rnStmts rn_expr (stmt:stmts) thing_inside
437 = rnStmt rn_expr stmt $ \ stmt' ->
438 rnStmts rn_expr stmts $ \ stmts' ->
439 thing_inside (stmt' : stmts')
441 rnStmt :: RnExprTy s -> RdrNameStmt -> (RenamedStmt -> RnMS s (a, FreeVars)) -> RnMS s (a, FreeVars)
442 -- Because of mutual recursion we have to pass in rnExpr.
444 rnStmt rn_expr (BindStmt pat expr src_loc) thing_inside
445 = pushSrcLocRn src_loc $
446 rn_expr expr `thenRn` \ (expr', fv_expr) ->
447 bindLocalsRn "pattern in do binding" binders $ \ new_binders ->
448 rnPat pat `thenRn` \ pat' ->
450 thing_inside (BindStmt pat' expr' src_loc) `thenRn` \ (result, fvs) ->
451 returnRn (result, fv_expr `unionNameSets` (fvs `minusNameSet` mkNameSet new_binders))
453 binders = collectPatBinders pat
455 rnStmt rn_expr (ExprStmt expr src_loc) thing_inside
456 = pushSrcLocRn src_loc $
457 rn_expr expr `thenRn` \ (expr', fv_expr) ->
458 thing_inside (ExprStmt expr' src_loc) `thenRn` \ (result, fvs) ->
459 returnRn (result, fv_expr `unionNameSets` fvs)
461 rnStmt rn_expr (GuardStmt expr src_loc) thing_inside
462 = pushSrcLocRn src_loc $
463 rn_expr expr `thenRn` \ (expr', fv_expr) ->
464 thing_inside (GuardStmt expr' src_loc) `thenRn` \ (result, fvs) ->
465 returnRn (result, fv_expr `unionNameSets` fvs)
467 rnStmt rn_expr (ReturnStmt expr) thing_inside
468 = rn_expr expr `thenRn` \ (expr', fv_expr) ->
469 thing_inside (ReturnStmt expr') `thenRn` \ (result, fvs) ->
470 returnRn (result, fv_expr `unionNameSets` fvs)
472 rnStmt rn_expr (LetStmt binds) thing_inside
473 = rnBinds binds $ \ binds' ->
474 thing_inside (LetStmt binds')
477 %************************************************************************
479 \subsubsection{Precedence Parsing}
481 %************************************************************************
483 @mkOpAppRn@ deals with operator fixities. The argument expressions
484 are assumed to be already correctly arranged. It needs the fixities
485 recorded in the OpApp nodes, because fixity info applies to the things
486 the programmer actually wrote, so you can't find it out from the Name.
488 Furthermore, the second argument is guaranteed not to be another
489 operator application. Why? Because the parser parses all
490 operator appications left-associatively.
493 mkOpAppRn :: RenamedHsExpr -> RenamedHsExpr -> Fixity -> RenamedHsExpr
494 -> RnMS s RenamedHsExpr
496 mkOpAppRn e1@(OpApp e11 op1 fix1 e12)
499 = addErrRn (precParseErr (get op1,fix1) (get op2,fix2)) `thenRn_`
500 returnRn (OpApp e1 op2 fix2 e2)
503 = mkOpAppRn e12 op2 fix2 e2 `thenRn` \ new_e ->
504 returnRn (OpApp e11 op1 fix1 new_e)
506 (nofix_error, rearrange_me) = compareFixity fix1 fix2
508 mkOpAppRn e1@(NegApp neg_arg neg_op)
510 fix2@(Fixity prec2 dir2)
513 = addErrRn (precParseErr (get neg_op,fix_neg) (get op2,fix2)) `thenRn_`
514 returnRn (OpApp e1 op2 fix2 e2)
517 = mkOpAppRn neg_arg op2 fix2 e2 `thenRn` \ new_e ->
518 returnRn (NegApp new_e neg_op)
520 fix_neg = Fixity 6 InfixL -- Precedence of unary negate is wired in as infixl 6!
521 (nofix_error, rearrange_me) = compareFixity fix_neg fix2
523 mkOpAppRn e1 op fix e2 -- Default case, no rearrangment
524 = ASSERT( right_op_ok fix e2 )
525 returnRn (OpApp e1 op fix e2)
529 -- Parser left-associates everything, but
530 -- derived instances may have correctly-associated things to
531 -- in the right operarand. So we just check that the right operand is OK
532 right_op_ok fix1 (OpApp _ _ fix2 _)
533 = not error_please && associate_right
535 (error_please, associate_right) = compareFixity fix1 fix2
536 right_op_ok fix1 other
539 -- Parser initially makes negation bind more tightly than any other operator
540 mkNegAppRn mode neg_arg neg_op
541 = ASSERT( not_op_app mode neg_arg )
542 returnRn (NegApp neg_arg neg_op)
544 not_op_app SourceMode (OpApp _ _ _ _) = False
545 not_op_app mode other = True
549 mkConOpPatRn :: RenamedPat -> Name -> Fixity -> RenamedPat
552 mkConOpPatRn p1@(ConOpPatIn p11 op1 fix1 p12)
555 = addErrRn (precParseErr (op1,fix1) (op2,fix2)) `thenRn_`
556 returnRn (ConOpPatIn p1 op2 fix2 p2)
559 = mkConOpPatRn p12 op2 fix2 p2 `thenRn` \ new_p ->
560 returnRn (ConOpPatIn p11 op1 fix1 new_p)
563 (nofix_error, rearrange_me) = compareFixity fix1 fix2
565 mkConOpPatRn p1@(NegPatIn neg_arg)
567 fix2@(Fixity prec2 dir2)
569 | prec2 > 6 -- Precedence of unary - is wired in as 6!
570 = addErrRn (precParseNegPatErr (op2,fix2)) `thenRn_`
571 returnRn (ConOpPatIn p1 op2 fix2 p2)
573 mkConOpPatRn p1 op fix p2 -- Default case, no rearrangment
574 = ASSERT( not_op_pat p2 )
575 returnRn (ConOpPatIn p1 op fix p2)
577 not_op_pat (ConOpPatIn _ _ _ _) = False
578 not_op_pat other = True
582 checkPrecMatch :: Bool -> RdrName -> RdrNameMatch -> RnMS s ()
584 checkPrecMatch False fn match
586 checkPrecMatch True op (PatMatch p1 (PatMatch p2 (GRHSMatch _)))
587 = checkPrec op p1 False `thenRn_`
589 checkPrecMatch True op _
590 = panic "checkPrecMatch"
592 checkPrec op (ConOpPatIn _ op1 _ _) right
593 = lookupFixity op `thenRn` \ op_fix@(Fixity op_prec op_dir) ->
594 lookupFixity op1 `thenRn` \ op1_fix@(Fixity op1_prec op1_dir) ->
596 inf_ok = op1_prec > op_prec ||
597 (op1_prec == op_prec &&
598 (op1_dir == InfixR && op_dir == InfixR && right ||
599 op1_dir == InfixL && op_dir == InfixL && not right))
602 info1 = (op1,op1_fix)
603 (infol, infor) = if right then (info, info1) else (info1, info)
605 checkRn inf_ok (precParseErr infol infor)
607 checkPrec op (NegPatIn _) right
608 = lookupFixity op `thenRn` \ op_fix@(Fixity op_prec op_dir) ->
609 checkRn (op_prec <= 6) (precParseNegPatErr (op,op_fix))
611 checkPrec op pat right
618 (compareFixity op1 op2) tells which way to arrange appication, or
619 whether there's an error.
622 compareFixity :: Fixity -> Fixity
623 -> (Bool, -- Error please
624 Bool) -- Associate to the right: a op1 (b op2 c)
625 compareFixity (Fixity prec1 dir1) (Fixity prec2 dir2)
626 = case prec1 `cmp` prec2 of
629 EQ_ -> case (dir1, dir2) of
630 (InfixR, InfixR) -> right
631 (InfixL, InfixL) -> left
634 right = (False, True)
635 left = (False, False)
636 error_please = (True, False)
639 %************************************************************************
641 \subsubsection{Literals}
643 %************************************************************************
645 When literals occur we have to make sure that the types and classes they involve
649 litOccurrence (HsChar _)
650 = addImplicitOccRn charType_name
652 litOccurrence (HsCharPrim _)
653 = addImplicitOccRn (getName charPrimTyCon)
655 litOccurrence (HsString _)
656 = addImplicitOccRn listType_name `thenRn_`
657 addImplicitOccRn charType_name
659 litOccurrence (HsStringPrim _)
660 = addImplicitOccRn (getName addrPrimTyCon)
662 litOccurrence (HsInt _)
663 = lookupImplicitOccRn numClass_RDR -- Int and Integer are forced in by Num
665 litOccurrence (HsFrac _)
666 = lookupImplicitOccRn fractionalClass_RDR `thenRn_`
667 lookupImplicitOccRn ratioDataCon_RDR
668 -- We have to make sure that the Ratio type is imported with
669 -- its constructor, because literals of type Ratio t are
670 -- built with that constructor.
672 litOccurrence (HsIntPrim _)
673 = addImplicitOccRn (getName intPrimTyCon)
675 litOccurrence (HsFloatPrim _)
676 = addImplicitOccRn (getName floatPrimTyCon)
678 litOccurrence (HsDoublePrim _)
679 = addImplicitOccRn (getName doublePrimTyCon)
681 litOccurrence (HsLitLit _)
682 = lookupImplicitOccRn ccallableClass_RDR
686 %************************************************************************
688 \subsubsection{Errors}
690 %************************************************************************
693 dupFieldErr str (dup:rest) sty
694 = hcat [ptext SLIT("duplicate field name `"),
696 ptext SLIT("' in record "), text str]
699 = sep [ptext SLIT("prefix `-' not applied to literal in pattern"), ppr sty pat]
701 precParseNegPatErr op sty
702 = hang (ptext SLIT("precedence parsing error"))
703 4 (hcat [ptext SLIT("prefix `-' has lower precedence than "),
705 ptext SLIT(" in pattern")])
707 precParseErr op1 op2 sty
708 = hang (ptext SLIT("precedence parsing error"))
709 4 (hcat [ptext SLIT("cannot mix "), pp_op sty op1, ptext SLIT(" and "), pp_op sty op2,
710 ptext SLIT(" in the same infix expression")])
712 nonStdGuardErr guard sty
713 = hang (ptext SLIT("accepting non-standard pattern guards (-fglasgow-exts to suppress this message)"))
716 pp_op sty (op, fix) = hcat [ppr sty op, space, parens (ppr sty fix)]