79 lines
1.5 KiB
Haskell
Raw Normal View History

2020-06-09 15:56:11 +04:00
module AST.Find where
import Control.Monad
import AST.Types
import AST.Scope
import AST.Parser
2020-06-09 15:56:11 +04:00
import Parser
2020-06-09 15:56:11 +04:00
import Tree
import Range
import Lattice
import Pretty
2020-07-08 20:31:42 +04:00
import Product
2020-06-09 15:56:11 +04:00
import Debug.Trace
findScopedDecl
2020-07-08 20:31:42 +04:00
:: ( Contains [ScopedDecl] xs
, Contains Range xs
, Contains (Maybe Category) xs
2020-06-09 15:56:11 +04:00
)
=> Range
2020-07-08 20:31:42 +04:00
-> Pascal (Product xs)
2020-06-09 15:56:11 +04:00
-> Maybe ScopedDecl
findScopedDecl pos tree = do
point <- lookupTree pos tree
2020-07-08 20:31:42 +04:00
let info = infoOf point
let fullEnv = getElem info
do
cat <- getElem info
let filtered = filter (ofCategory cat) fullEnv
lookupEnv (ppToText $ void point) filtered
2020-06-09 15:56:11 +04:00
definitionOf
2020-07-08 20:31:42 +04:00
:: ( Contains [ScopedDecl] xs
, Contains Range xs
, Contains (Maybe Category) xs
2020-06-09 15:56:11 +04:00
)
=> Range
2020-07-08 20:31:42 +04:00
-> Pascal (Product xs)
2020-06-09 15:56:11 +04:00
-> Maybe Range
definitionOf pos tree =
_sdOrigin <$> findScopedDecl pos tree
typeOf
2020-07-08 20:31:42 +04:00
:: ( Contains [ScopedDecl] xs
, Contains Range xs
, Contains (Maybe Category) xs
2020-06-09 15:56:11 +04:00
)
=> Range
2020-07-08 20:31:42 +04:00
-> Pascal (Product xs)
2020-06-09 15:56:11 +04:00
-> Maybe (Either (Pascal ()) Kind)
typeOf pos tree =
_sdType =<< findScopedDecl pos tree
implementationOf
2020-07-08 20:31:42 +04:00
:: ( Contains [ScopedDecl] xs
, Contains Range xs
, Contains (Maybe Category) xs
2020-06-09 15:56:11 +04:00
)
=> Range
2020-07-08 20:31:42 +04:00
-> Pascal (Product xs)
2020-06-09 15:56:11 +04:00
-> Maybe Range
implementationOf pos tree =
_sdBody =<< findScopedDecl pos tree
referencesOf
2020-07-08 20:31:42 +04:00
:: ( Contains [ScopedDecl] xs
, Contains Range xs
, Contains (Maybe Category) xs
)
=> Range
2020-07-08 20:31:42 +04:00
-> Pascal (Product xs)
-> Maybe [Range]
referencesOf pos tree =
_sdRefs <$> findScopedDecl pos tree