diff options
author | alexwl <alexey.a.kiryushin@gmail.com> | 2018-10-09 23:13:07 +0300 |
---|---|---|
committer | alexwl <alexey.a.kiryushin@gmail.com> | 2018-10-09 23:13:07 +0300 |
commit | 166265e93de140c4a33f7a61bc004fb64be18275 (patch) | |
tree | 7773bb4f34604637ad42a9d7948593737f2b3c9d /src/HaskellCodeExplorer/AST/TypecheckedSource.hs | |
parent | f38daf67730fe31b865528eb972c619857e62a5c (diff) |
WIP. It compiles with ghc-8.4.3, but not all features of the indexer are supported yet.
Diffstat (limited to 'src/HaskellCodeExplorer/AST/TypecheckedSource.hs')
-rw-r--r-- | src/HaskellCodeExplorer/AST/TypecheckedSource.hs | 128 |
1 files changed, 95 insertions, 33 deletions
diff --git a/src/HaskellCodeExplorer/AST/TypecheckedSource.hs b/src/HaskellCodeExplorer/AST/TypecheckedSource.hs index f97c33b..4dfbd8b 100644 --- a/src/HaskellCodeExplorer/AST/TypecheckedSource.hs +++ b/src/HaskellCodeExplorer/AST/TypecheckedSource.hs @@ -80,6 +80,7 @@ import HsSyn , selectorAmbiguousFieldOcc ) import HscTypes (TypeEnv, lookupTypeEnv) +import HsExtension (GhcTc) import Id (idType) import IdInfo (IdDetails(..)) import InstEnv @@ -541,11 +542,15 @@ tidyType typ = do let (tidyEnv', typ') = tidyOpenType tidyEnv typ modify' (\s -> s {astStateTidyEnv = tidyEnv'}) return typ' - -foldTypecheckedSource :: LHsBinds Id -> State ASTState () + +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldTypecheckedSource :: LHsBinds GhcTc -> State ASTState () +#endif foldTypecheckedSource = foldLHsBindsLR -foldLHsExpr :: LHsExpr Var -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsExpr :: LHsExpr GhcTc -> State ASTState (Maybe Type) +#endif foldLHsExpr (L span (HsVar (L _ identifier))) = restoreTidyEnv $ do (identifier', mbTypes) <- tidyIdentifier identifier @@ -801,8 +806,10 @@ foldLHsExpr (L span (HsWrap wrapper expr)) = Composite -> return () -- Not sure if it is possible typ <- foldLHsExpr (L span expr) return $ applyWrapper wrapper <$> typ - -foldHsRecFields :: HsRecFields Id (LHsExpr Id) -> State ASTState (Maybe Type) + +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldHsRecFields :: HsRecFields GhcTc (LHsExpr GhcTc) -> State ASTState (Maybe Type) +#endif foldHsRecFields HsRecFields {..} = do let userWritten = case rec_dotdot of @@ -810,8 +817,10 @@ foldHsRecFields HsRecFields {..} = do Nothing -> id mapM_ foldLHsRecField $ userWritten rec_flds return Nothing - -foldLHsRecField :: LHsRecField Id (LHsExpr Id) -> State ASTState (Maybe Type) + +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsRecField :: LHsRecField GhcTc (LHsExpr GhcTc) -> State ASTState (Maybe Type) +#endif foldLHsRecField (L span (HsRecField (L idSpan (FieldOcc _ identifier)) arg pun)) = restoreTidyEnv $ do (identifier', mbTypes) <- tidyIdentifier identifier @@ -820,7 +829,9 @@ foldLHsRecField (L span (HsRecField (L idSpan (FieldOcc _ identifier)) arg pun)) unless pun $ void (foldLHsExpr arg) return . Just . varType $ identifier' -foldLHsRecUpdField :: LHsRecUpdField Id -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsRecUpdField :: LHsRecUpdField GhcTc -> State ASTState (Maybe Type) +#endif foldLHsRecUpdField (L span (HsRecField (L idSpan recField) arg pun)) = restoreTidyEnv $ do let selectorId = selectorAmbiguousFieldOcc recField @@ -844,7 +855,9 @@ data TupArg | TupArgMissing deriving (Show, Eq) -foldLHsTupArg :: LHsTupArg Id -> State ASTState (Maybe Type, TupArg) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsTupArg :: LHsTupArg GhcTc -> State ASTState (Maybe Type, TupArg) +#endif foldLHsTupArg (L _span (Present expr)) = restoreTidyEnv $ do typ <- foldLHsExpr expr @@ -858,31 +871,41 @@ foldLHsTupArg (L _ (Missing typ)) = typ' <- tidyType typ return (Just typ', TupArgMissing) -foldLMatch :: LMatch Id (LHsExpr Var) -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLMatch :: LMatch GhcTc (LHsExpr GhcTc) -> State ASTState (Maybe Type) +#endif foldLMatch (L _span Match {..}) = do mapM_ foldLPat m_pats _ <- foldGRHSs m_grhss return Nothing - -foldLMatchCmd :: LMatch Id (LHsCmd Var) -> State ASTState (Maybe Type) + +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLMatchCmd :: LMatch GhcTc (LHsCmd GhcTc) -> State ASTState (Maybe Type) +#endif foldLMatchCmd (L _span Match {..}) = do mapM_ foldLPat m_pats _ <- foldGRHSsCmd m_grhss return Nothing -foldGRHSsCmd :: GRHSs Id (LHsCmd Id) -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldGRHSsCmd :: GRHSs GhcTc (LHsCmd GhcTc) -> State ASTState (Maybe Type) +#endif foldGRHSsCmd GRHSs {..} = do mapM_ foldLGRHSCmd grhssGRHSs _ <- foldHsLocalBindsLR (unLoc grhssLocalBinds) return Nothing -foldGRHSs :: GRHSs Id (LHsExpr Var) -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldGRHSs :: GRHSs GhcTc (LHsExpr GhcTc) -> State ASTState (Maybe Type) +#endif foldGRHSs GRHSs {..} = do mapM_ foldLGRHS grhssGRHSs _ <- foldHsLocalBindsLR (unLoc grhssLocalBinds) return Nothing -foldLStmtLR :: LStmtLR Id Id (LHsExpr Var) -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLStmtLR :: LStmtLR GhcTc GhcTc (LHsExpr GhcTc) -> State ASTState (Maybe Type) +#endif foldLStmtLR (L span (LastStmt body _ _)) = do typ <- foldLHsExpr body addExprInfo span typ "LastStmt" Composite @@ -916,10 +939,16 @@ foldLStmtLR (L span (ApplicativeStmt args _ typ)) = addExprInfo span (Just typ') "ApplicativeStmt" Composite return Nothing -foldApplicativeArg :: ApplicativeArg Id Id -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldApplicativeArg :: ApplicativeArg GhcTc GhcTc -> State ASTState (Maybe Type) +#endif foldApplicativeArg appArg = case appArg of +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) + ApplicativeArgOne pat expr _bool -> do +#else ApplicativeArgOne pat expr -> do +#endif _ <- foldLPat pat _ <- foldLHsExpr expr return Nothing @@ -927,9 +956,10 @@ foldApplicativeArg appArg = _ <- mapM_ foldLStmtLR exprStmts _ <- foldLPat pat return Nothing - -foldLStmtLRCmd :: LStmtLR Id Id (LHsCmd Var) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLStmtLRCmd :: LStmtLR GhcTc GhcTc (LHsCmd GhcTc) -> State ASTState (Maybe Type) +#endif foldLStmtLRCmd (L span (LastStmt body _syntaxExpr _)) = do typ <- foldLHsCmd body addExprInfo span typ "LastStmt Cmd" Composite @@ -962,43 +992,57 @@ foldLStmtLRCmd (L span (ApplicativeStmt args _ typ)) = mapM_ (foldApplicativeArg . snd) args addExprInfo span (Just typ') "ApplicativeStmt Cmd" Composite return Nothing - -foldLGRHS :: LGRHS Id (LHsExpr Id) -> State ASTState (Maybe Type) + +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLGRHS :: LGRHS GhcTc (LHsExpr GhcTc) -> State ASTState (Maybe Type) +#endif foldLGRHS (L _span (GRHS guards body)) = do typ <- foldLHsExpr body mapM_ foldLStmtLR guards return typ - -foldLGRHSCmd :: LGRHS Id (LHsCmd Var) -> State ASTState (Maybe Type) + +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLGRHSCmd :: LGRHS GhcTc (LHsCmd GhcTc) -> State ASTState (Maybe Type) +#endif foldLGRHSCmd (L _span (GRHS guards body)) = do typ <- foldLHsCmd body mapM_ foldLStmtLR guards return typ -foldParStmtBlock :: ParStmtBlock Id Id -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldParStmtBlock :: ParStmtBlock GhcTc GhcTc -> State ASTState (Maybe Type) +#endif foldParStmtBlock (ParStmtBlock exprStmts _ids _syntaxExpr) = do mapM_ foldLStmtLR exprStmts return Nothing -foldHsLocalBindsLR :: HsLocalBindsLR Id Id -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldHsLocalBindsLR :: HsLocalBindsLR GhcTc GhcTc -> State ASTState (Maybe Type) +#endif foldHsLocalBindsLR (HsValBinds binds) = do _ <- foldHsValBindsLR binds return Nothing foldHsLocalBindsLR (HsIPBinds _binds) = return Nothing foldHsLocalBindsLR EmptyLocalBinds = return Nothing -foldHsValBindsLR :: HsValBindsLR Id Var -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldHsValBindsLR :: HsValBindsLR GhcTc GhcTc -> State ASTState (Maybe Type) +#endif foldHsValBindsLR (ValBindsIn _ _) = return Nothing foldHsValBindsLR (ValBindsOut binds _) = do _ <- mapM_ (foldLHsBindsLR . snd) binds return Nothing -foldLHsBindsLR :: LHsBinds Id -> State ASTState () +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsBindsLR :: LHsBinds GhcTc -> State ASTState () +#endif foldLHsBindsLR = mapM_ (`foldLHsBindLR` Nothing) . bagToList -foldLHsBindLR :: LHsBindLR Id Var +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsBindLR :: LHsBindLR GhcTc GhcTc -> Maybe Id -- ^ Polymorphic id -> State ASTState (Maybe Type) +#endif foldLHsBindLR (L _span FunBind {..}) mbPolyId | mg_origin fun_matches == FromSource = restoreTidyEnv $ do @@ -1024,12 +1068,17 @@ foldLHsBindLR (L _ AbsBinds {..}) _ = do mapM_ (\(bind, typ) -> foldLHsBindLR bind (Just typ)) $ zip (bagToList abs_binds) (map abe_poly abs_exports) return Nothing +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +#else foldLHsBindLR (L _ AbsBindsSig {..}) _ = do _ <- foldLHsBindLR abs_sig_bind (Just abs_sig_export) return Nothing +#endif foldLHsBindLR (L _ (PatSynBind PSB {..})) _ = restoreTidyEnv $ do _ <- foldLPat psb_def +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +#else _ <- let addId :: GenLocated SrcSpan Id -> State ASTState () addId (L span i) = do @@ -1043,9 +1092,12 @@ foldLHsBindLR (L _ (PatSynBind PSB {..})) _ = (\(RecordPatSynField selId patVar) -> addId selId >> addId patVar) recs +#endif return Nothing -foldLPat :: LPat Id -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLPat :: LPat GhcTc -> State ASTState (Maybe Type) +#endif foldLPat (L span (VarPat (L _ identifier))) = do (identifier', _) <- tidyIdentifier identifier addIdentifierToIdSrcSpanMap span identifier' Nothing @@ -1151,9 +1203,11 @@ foldLPat (L span p@(CoPat _ pat typ)) = do _ <- foldLPat (L span pat) return Nothing +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) foldHsConPatDetails - :: HsConPatDetails Id + :: HsConPatDetails GhcTc -> State ASTState (Maybe Type) +#endif foldHsConPatDetails (PrefixCon args) = do _ <- mapM_ foldLPat args return Nothing @@ -1165,7 +1219,9 @@ foldHsConPatDetails (InfixCon arg1 arg2) = do _ <- foldLPat arg2 return Nothing -foldHsRecFieldsPat :: HsRecFields Id (LPat Id) -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldHsRecFieldsPat :: HsRecFields GhcTc (LPat GhcTc) -> State ASTState (Maybe Type) +#endif foldHsRecFieldsPat HsRecFields {..} = do let onlyUserWritten = case rec_dotdot of @@ -1174,20 +1230,26 @@ foldHsRecFieldsPat HsRecFields {..} = do _ <- mapM_ foldLHsRecFieldPat $ onlyUserWritten rec_flds return Nothing -foldLHsRecFieldPat :: LHsRecField Id (LPat Id) -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsRecFieldPat :: LHsRecField GhcTc (LPat GhcTc) -> State ASTState (Maybe Type) +#endif foldLHsRecFieldPat (L _ (HsRecField (L idSpan (FieldOcc _ identifier)) arg pun)) = do (identifier', mbTypes) <- tidyIdentifier identifier addIdentifierToIdSrcSpanMap idSpan identifier' mbTypes unless pun $ void $ foldLPat arg return . Just . varType $ identifier' -foldLHsCmdTop :: LHsCmdTop Id -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsCmdTop :: LHsCmdTop GhcTc -> State ASTState (Maybe Type) +#endif foldLHsCmdTop (L span (HsCmdTop cmd _ _ _)) = do mbTyp <- foldLHsCmd cmd addExprInfo span mbTyp "HsCmdTop" Composite return mbTyp -foldLHsCmd :: LHsCmd Id -> State ASTState (Maybe Type) +#if MIN_VERSION_GLASGOW_HASKELL(8,4,3,0) +foldLHsCmd :: LHsCmd GhcTc -> State ASTState (Maybe Type) +#endif foldLHsCmd (L _ (HsCmdArrApp expr1 expr2 _ _ _)) = do _ <- foldLHsExpr expr1 _ <- foldLHsExpr expr2 |