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 :: [Char] -> [[Char]] -> IO ()
main = forall cfg.
cfg
-> [FunOptDescr cfg]
-> [Char]
-> ([[Char]] -> cfg -> Maybe (IO ()))
-> [Char]
-> [[Char]]
-> IO ()
mainWithOptions () [] [Char]
"program line col" forall a b. (a -> b) -> a -> b
$ \[[Char]]
args () ->
case [[Char]]
args of
[[Char]
file, [Char]
line, [Char]
col] -> do
Int
line' <- forall a. Read a => [Char] -> Maybe a
readMaybe [Char]
line
Int
col' <- forall a. Read a => [Char] -> Maybe a
readMaybe [Char]
col
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ do
(Warnings
_, Imports
imports, VNameSource
_) <- forall (m :: * -> *).
MonadIO m =>
[Char] -> m (Warnings, Imports, VNameSource)
readProgramOrDie [Char]
file
case Imports -> Pos -> Maybe AtPos
atPos Imports
imports forall a b. (a -> b) -> a -> b
$ [Char] -> Int -> Int -> Int -> Pos
Pos [Char]
file Int
line' Int
col' Int
0 of
Maybe AtPos
Nothing -> [Char] -> IO ()
putStrLn [Char]
"No information available."
Just (AtName QualName VName
qn Maybe BoundTo
def Loc
loc) -> do
[Char] -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [Char]
"Name: " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyString QualName VName
qn
[Char] -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [Char]
"Position: " forall a. [a] -> [a] -> [a]
++ forall a. Located a => a -> [Char]
locStr (forall a. Located a => a -> SrcLoc
srclocOf Loc
loc)
case Maybe BoundTo
def of
Maybe BoundTo
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Just (BoundTerm StructType
t Loc
defloc) -> do
[Char] -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [Char]
"Type: " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyString StructType
t
[Char] -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [Char]
"Definition: " forall a. [a] -> [a] -> [a]
++ forall a. Located a => a -> [Char]
locStr (forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
Just (BoundType Loc
defloc) ->
[Char] -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [Char]
"Definition: " forall a. [a] -> [a] -> [a]
++ forall a. Located a => a -> [Char]
locStr (forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
Just (BoundModule Loc
defloc) ->
[Char] -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [Char]
"Definition: " forall a. [a] -> [a] -> [a]
++ forall a. Located a => a -> [Char]
locStr (forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
Just (BoundModuleType Loc
defloc) ->
[Char] -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [Char]
"Definition: " forall a. [a] -> [a] -> [a]
++ forall a. Located a => a -> [Char]
locStr (forall a. Located a => a -> SrcLoc
srclocOf Loc
defloc)
[[Char]]
_ -> forall a. Maybe a
Nothing