<commit_before>{-# OPTIONS -cpp -fglasgow-exts #-}
{-# OPTIONS -fno-warn-unused-matches -fno-warn-unused-binds -fno-warn-name-shadowing #-}
--
-- Copyright (C) 2004 <NAME> - http://www.cse.unsw.edu.au/~dons
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this library; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
-- USA
--

--
-- Based on $fptools/ghc/compiler/iface/BinIface.hs
--
--  (c) The University of Glasgow 2002
--
-- Binary interface file support.
--

--
-- This provides the "Binary" instances for the Iface type such that we
-- can parse binary representations of that type. i.e. from .hi files
--
-- The main problem we have is that all the stuff we don't care about,
-- we just want to read in to a string. So this has to be hand-hacked
-- somewhat.
--
-- The "Binary" class for hs-plugins only includes a get method. We
-- don't do any writing. Saves us having to properly reconstruct the
-- abstract syntax, which would pull in *way* too much of GHC.
--



module Language.Hi.Parser ( readIface, module Language.Hi.Syntax ) where

import Language.Hi.Syntax
import Language.Hi.Binary
import Language.Hi.FastString

import GHC.Word

#include "../../../../config.h"

-- ---------------------------------------------------------------------------
-- how to get there from here

readIface :: FilePath -> IO Iface
readIface hi_path = getBinFileWithDict hi_path

-- ---------------------------------------------------------------------
-- All the Binary instances
--
-- Reading a binary interface into ParsedIface
--
-- We pull the trick of only reading up to the point we need
--

instance Binary Iface where
    get bh = do
            version   <- get bh :: IO String
            build_tag <- get bh :: IO Word8     -- 'way' flag

#if __GLASGOW_HASKELL__ >= 604
            mod_name  <- get bh :: IO FastString
            _is_boot  <- get bh :: IO Bool
            let pkg_name = mkFastString "unknown"  -- >=604 has no package field
#elif CABAL == 1 && __GLASGOW_HASKELL__ == 603
            mod_name <- get bh :: IO FastString
            let pkg_name = mkFastString "unknown"
#else /* <= 622 */
            mod_name  <- get bh :: IO FastString
            pkg_name  <- get bh :: IO FastString
#endif
            mod_vers  <- get bh :: IO Version
            orphan    <- get bh :: IO Bool
            deps      <- get bh :: IO Dependencies

            get bh :: IO (Bin Int) -- fake a lazyGet for [Usage]
            usages    <- get bh :: IO [Usage]

            exports   <- get bh :: IO [IfaceExport]

--      (exp_vers  :: Version)              <- get bh
--      (fixities  :: [(OccName,Fixity)])   <- get bh
--      (deprecs   :: [IfaceDeprec])        <- get bh<commit_msg>Fixed 'way' tag in the Hi parser.<commit_after>{-# OPTIONS -cpp -fglasgow-exts #-}
{-# OPTIONS -fno-warn-unused-matches -fno-warn-unused-binds -fno-warn-name-shadowing #-}
--
-- Copyright (C) 2004 <NAME> - http://www.cse.unsw.edu.au/~dons
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this library; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
-- USA
--

--
-- Based on $fptools/ghc/compiler/iface/BinIface.hs
--
--  (c) The University of Glasgow 2002
--
-- Binary interface file support.
--

--
-- This provides the "Binary" instances for the Iface type such that we
-- can parse binary representations of that type. i.e. from .hi files
--
-- The main problem we have is that all the stuff we don't care about,
-- we just want to read in to a string. So this has to be hand-hacked
-- somewhat.
--
-- The "Binary" class for hs-plugins only includes a get method. We
-- don't do any writing. Saves us having to properly reconstruct the
-- abstract syntax, which would pull in *way* too much of GHC.
--



module Language.Hi.Parser ( readIface, module Language.Hi.Syntax ) where

import Language.Hi.Syntax
import Language.Hi.Binary
import Language.Hi.FastString


#include "../../../../config.h"

-- ---------------------------------------------------------------------------
-- how to get there from here

readIface :: FilePath -> IO Iface
readIface hi_path = getBinFileWithDict hi_path

-- ---------------------------------------------------------------------
-- All the Binary instances
--
-- Reading a binary interface into ParsedIface
--
-- We pull the trick of only reading up to the point we need
--

instance Binary Iface where
    get bh = do
            version   <- get bh :: IO String
            build_tag <- get bh :: IO String     -- 'way' flag

#if __GLASGOW_HASKELL__ >= 604
            mod_name  <- get bh :: IO FastString
            _is_boot  <- get bh :: IO Bool
            let pkg_name = mkFastString "unknown"  -- >=604 has no package field
#elif CABAL == 1 && __GLASGOW_HASKELL__ == 603
            mod_name <- get bh :: IO FastString
            let pkg_name = mkFastString "unknown"
#else /* <= 622 */
            mod_name  <- get bh :: IO FastString
            pkg_name  <- get bh :: IO FastString
#endif
            mod_vers  <- get bh :: IO Version
            orphan    <- get bh :: IO Bool
            deps      <- get bh :: IO Dependencies

            get bh :: IO (Bin Int) -- fake a lazyGet for [Usage]
            usages    <- get bh :: IO [Usage]

            exports   <- get bh :: IO [IfaceExport]

--      (exp_vers  :: Version)              <- get bh
--      (fixities  :: [(OccName,Fixity)])   <- get bh
--      (deprecs   :: [IfaceDeprec])        <- get bh
{'fraction_non_alphanumeric': 0.14764697038039393, 'fraction_numerical': 0.011276499774470004, 'mean_word_length': 1.992352676563203, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4526520', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1878, 'n_words': 795}