77 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 Tree
import Range
import Pretty
2020-07-08 20:31:42 +04:00
import Product
2020-06-09 15:56:11 +04:00
2020-07-10 15:11:49 +04:00
-- import Debug.Trace
2020-06-09 15:56:11 +04:00
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
2020-07-10 15:11:49 +04:00
pt <- lookupTree pos tree
let info = infoOf pt
2020-07-08 20:31:42 +04:00
let fullEnv = getElem info
do
2020-07-10 15:11:49 +04:00
categ <- getElem info
let filtered = filter (ofCategory categ) fullEnv
lookupEnv (ppToText $ void pt) 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