-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from phischu/v0.5.0
All changes for version 0.5.0
- Loading branch information
Showing
273 changed files
with
2,495 additions
and
4,204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module Main where | ||
|
||
import Language.Haskell.Exts.Annotated | ||
import qualified Language.Haskell.Exts as UnAnn (Name(Ident)) | ||
import Language.Haskell.Names | ||
import Language.Haskell.Names.Interfaces | ||
import Distribution.HaskellSuite | ||
import Distribution.Simple.Compiler | ||
|
||
import Data.Maybe | ||
import Data.List | ||
import Data.Proxy | ||
import qualified Data.Foldable as Foldable | ||
import Text.Printf | ||
import Control.Applicative | ||
import Control.Monad | ||
|
||
main :: IO () | ||
main = do | ||
|
||
-- read the program's source from stdin | ||
source <- getContents | ||
|
||
let | ||
-- parse the program (using haskell-src-exts) | ||
ast = fromParseResult $ | ||
parseModuleWithMode defaultParseMode {parseFilename="stdin"} source | ||
|
||
-- get all installed packages (user and global) | ||
pkgs <- | ||
(++) <$> | ||
getInstalledPackages (Proxy :: Proxy NamesDB) UserPackageDB <*> | ||
getInstalledPackages (Proxy :: Proxy NamesDB) GlobalPackageDB | ||
|
||
headUsages <- evalNamesModuleT (findHeads ast) pkgs | ||
|
||
forM_ headUsages $ \loc -> | ||
printf "Prelude.head is used at %s\n" (prettyPrint $ srcInfoSpan loc) | ||
|
||
when (null headUsages) $ | ||
printf "Congratulations! Your code doesn't use Prelude.head\n" | ||
|
||
-- this is a computation in a ModuleT monad, because we need access to | ||
-- modules' interfaces | ||
findHeads :: Module SrcSpanInfo -> ModuleT [Symbol] IO [SrcSpanInfo] | ||
findHeads ast = do | ||
-- first of all, figure out the canonical name of "Prelude.head" | ||
-- (hint: it's "GHC.List.head") | ||
symbols <- fromMaybe (error "Prelude not found") <$> getModuleInfo "Prelude" | ||
let | ||
-- we walk through all values defined in Prelude and look for | ||
-- one with name "head" | ||
headSymbol = | ||
fromMaybe (error "Prelude.head not found") (listToMaybe (do | ||
symbol <- symbols | ||
guard (symbolName symbol == UnAnn.Ident "head") | ||
return symbol)) | ||
|
||
-- annotate our ast with name binding information | ||
annotatedAst <- | ||
annotateModule | ||
Haskell2010 -- base language | ||
[] -- set of extensions | ||
ast | ||
|
||
|
||
let | ||
-- get list of all annotations | ||
annotations = Foldable.toList annotatedAst | ||
|
||
-- look for headSymbol | ||
headUsages = nub (do | ||
Scoped (GlobalSymbol globalSymbol _) location <- annotations | ||
guard (globalSymbol == headSymbol) | ||
return location) | ||
|
||
return headUsages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Name: hs-gen-iface | ||
Version: 0.2 | ||
Version: 0.5.0 | ||
License: MIT | ||
License-file: LICENSE | ||
Author: Roman Cheplyaka | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"origin":{"name":"!","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"//","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"accum","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"accumArray","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"array","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"assocs","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"bounds","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"elems","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"indices","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"ixmap","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"listArray","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"value"},{"origin":{"name":"inRange","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"method","class":{"name":"Ix","module":"GHC.Arr","package":"base-4.7.0.0"}},{"origin":{"name":"index","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"method","class":{"name":"Ix","module":"GHC.Arr","package":"base-4.7.0.0"}},{"origin":{"name":"range","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"method","class":{"name":"Ix","module":"GHC.Arr","package":"base-4.7.0.0"}},{"origin":{"name":"rangeSize","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"method","class":{"name":"Ix","module":"GHC.Arr","package":"base-4.7.0.0"}},{"origin":{"name":"Array","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"data"},{"origin":{"name":"Ix","module":"GHC.Arr","package":"base-4.7.0.0"},"fixity":null,"entity":"class"}] | ||
[{"name":"inRange","class":"Ix","entity":"method","module":"GHC.Arr"},{"name":"index","class":"Ix","entity":"method","module":"GHC.Arr"},{"name":"range","class":"Ix","entity":"method","module":"GHC.Arr"},{"name":"rangeSize","class":"Ix","entity":"method","module":"GHC.Arr"},{"name":"Ix","entity":"class","module":"GHC.Arr"},{"name":"Array","entity":"data","module":"GHC.Arr"},{"name":"array","entity":"value","module":"GHC.Arr"},{"name":"listArray","entity":"value","module":"GHC.Arr"},{"name":"accumArray","entity":"value","module":"GHC.Arr"},{"name":"!","entity":"value","module":"GHC.Arr"},{"name":"bounds","entity":"value","module":"GHC.Arr"},{"name":"indices","entity":"value","module":"GHC.Arr"},{"name":"elems","entity":"value","module":"GHC.Arr"},{"name":"assocs","entity":"value","module":"GHC.Arr"},{"name":"//","entity":"value","module":"GHC.Arr"},{"name":"accum","entity":"value","module":"GHC.Arr"},{"name":"ixmap","entity":"value","module":"GHC.Arr"}] |
Oops, something went wrong.