module Futhark.CLI.Query (main) where
import Futhark.Compiler
import Futhark.Util.Loc
import Futhark.Util.Options
import Language.Futhark.Query
import Language.Futhark.Syntax
import Text.Read (readMaybe)
main :: String -> [String] -> IO ()
main :: String -> [String] -> IO ()
main = ()
-> [FunOptDescr ()]
-> String
-> ([String] -> () -> Maybe (IO ()))
-> String
-> [String]
-> IO ()
forall cfg.
cfg
-> [FunOptDescr cfg]
-> String
-> ([String] -> cfg -> Maybe (IO ()))
-> String
-> [String]
-> IO ()
mainWithOptions () [] String
"program line col" (([String] -> () -> Maybe (IO ())) -> String -> [String] -> IO ())
-> ([String] -> () -> Maybe (IO ())) -> String -> [String] -> IO ()
forall a b. (a -> b) -> a -> b
$ \[String]
args () ->
case [String]
args of
[String
file, String
line, String
col] -> do
Int
line' <- String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe String
line
Int
col' <- String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe String
col
IO () -> Maybe (IO ())
forall a. a -> Maybe a
Just (IO () -> Maybe (IO ())) -> IO () -> Maybe (IO ())
forall a b. (a -> b) -> a -> b
$ do
(Warnings
_, Imports
imports, VNameSource
_) <- String -> IO (Warnings, Imports, VNameSource)
forall (m :: * -> *).
MonadIO m =>
String -> m (Warnings, Imports, VNameSource)
readProgramOrDie String
file
case Imports -> Pos -> Maybe AtPos
atPos Imports
imports (Pos -> Maybe AtPos) -> Pos -> Maybe AtPos
forall a b. (a -> b) -> a -> b
$ String -> Int -> Int -> Int -> Pos
Pos String
file Int
line' Int
col' Int
0 of
Maybe AtPos
Nothing -> String -> IO ()
putStrLn String
"No information available."
Just (AtName QualName VName
qn Maybe BoundTo
def Loc
loc) -> do
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Name: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ QualName VName -> String
forall a. Pretty a => a -> String
pretty QualName VName
qn
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Position: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SrcLoc -> String
forall a. Located a => a -> String
locStr (Loc -> SrcLoc
forall a. Located a => a -> SrcLoc
srclocOf Loc
loc)
case Maybe BoundTo
def of
Maybe BoundTo
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just (BoundTerm StructType
t Loc
defloc) -> do
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Type: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ StructType -> String
forall a. Pretty a => a -> String
pretty StructType
t
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Definition: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SrcLoc -> String
forall a. Located a => a -> String
locStr (Loc -> SrcLoc
forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
Just (BoundType Loc
defloc) ->
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Definition: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SrcLoc -> String
forall a. Located a => a -> String
locStr (Loc -> SrcLoc
forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
Just (BoundModule Loc
defloc) ->
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Definition: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SrcLoc -> String
forall a. Located a => a -> String
locStr (Loc -> SrcLoc
forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
Just (BoundModuleType Loc
defloc) ->
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Definition: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SrcLoc -> String
forall a. Located a => a -> String
locStr (Loc -> SrcLoc
forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
[String]
_ -> Maybe (IO ())
forall a. Maybe a
Nothing