{-
Checks for
        (a) *some* type errors
        (b) locally-defined variables used but not defined


Note: unless -dverbose-stg is on, display of lint errors will result
in "panic: bOGUS_LVs".

WARNING:
~~~~~~~~

This module has suffered bit-rot; it is likely to yield lint errors
for Stg code that is currently perfectly acceptable for code
generation.  Solution: don't use it!  (KSW 2000-05).


************************************************************************
*                                                                      *
\subsection{``lint'' for various constructs}
*                                                                      *
************************************************************************

@lintStgBindings@ is the top-level interface function.
-}

lintStgBindings :: String -> [StgBinding] -> [StgBinding]

lintStgBindings whodunnit binds
  = {-# SCC "StgLint" #-}
    case (initL (lint_binds binds)) of
      Nothing  -> binds
      Just msg -> pprPanic "" (vcat [
                        text "*** Stg Lint ErrMsgs: in" <+>
                              text whodunnit <+> text "***",
                        msg,
                        text "*** Offending Program ***",
                        pprStgBindings binds,
                        text "*** End of Offense ***"])
  where
    lint_binds :: [StgBinding] -> LintM ()

    lint_binds [] = return ()
    lint_binds (bind:binds) = do
        binders <- lintStgBinds bind
        addInScopeVars binders $
            lint_binds binds
lintStgBindings :: String -> [StgBinding] -> [StgBinding]
lintStgBindings whodunnit binds
  = {-# SCC "StgLint" #-}
    case (initL (lint_binds binds)) of
      Nothing  -> binds
      Just msg -> pprPanic "" (vcat [
                        text "*** Stg Lint ErrMsgs: in" <+>
                              text whodunnit <+> text "***",
                        msg,
                        text "*** Offending Program ***",
                        pprStgBindings binds,
                        text "*** End of Offense ***"])
  where
    lint_binds :: [StgBinding] -> LintM ()

    lint_binds [] = return ()
    lint_binds (bind:binds) = do
        binders <- lintStgBinds bind
        addInScopeVars binders $
            lint_binds binds
lintStgBindings whodunnit binds
  = {-# SCC "StgLint" #-}
    case (initL (lint_binds binds)) of
      Nothing  -> binds
      Just msg -> pprPanic "" (vcat [
                        text "*** Stg Lint ErrMsgs: in" <+>
                              text whodunnit <+> text "***",
                        msg,
                        text "*** Offending Program ***",
                        pprStgBindings binds,
                        text "*** End of Offense ***"])
  where
    lint_binds :: [StgBinding] -> LintM ()

    lint_binds [] = return ()
    lint_binds (bind:binds) = do
        binders <- lintStgBinds bind
        addInScopeVars binders $
            lint_binds binds