2020-06-09 15:56:11 +04:00
|
|
|
|
|
|
|
module AST.Find where
|
|
|
|
|
|
|
|
import Control.Monad
|
|
|
|
|
|
|
|
import AST.Types
|
|
|
|
import AST.Scope
|
2020-06-10 22:37:02 +04:00
|
|
|
import AST.Parser
|
2020-06-09 15:56:11 +04:00
|
|
|
|
2020-06-10 22:37:02 +04:00
|
|
|
import Parser
|
2020-06-09 15:56:11 +04:00
|
|
|
import Tree
|
|
|
|
import Range
|
|
|
|
import Lattice
|
2020-06-10 22:37:02 +04:00
|
|
|
import Pretty
|
2020-06-09 15:56:11 +04:00
|
|
|
|
|
|
|
import Debug.Trace
|
|
|
|
|
|
|
|
findScopedDecl
|
2020-06-17 22:05:44 +04:00
|
|
|
:: ( HasLocalScope info
|
2020-06-09 15:56:11 +04:00
|
|
|
, HasRange info
|
|
|
|
)
|
|
|
|
=> Range
|
|
|
|
-> Pascal info
|
|
|
|
-> Maybe ScopedDecl
|
|
|
|
findScopedDecl pos tree = do
|
2020-06-10 22:37:02 +04:00
|
|
|
point <- lookupTree pos tree
|
2020-06-17 22:05:44 +04:00
|
|
|
lookupEnv (ppToText $ void point) (getLocalScope (infoOf point))
|
2020-06-09 15:56:11 +04:00
|
|
|
|
|
|
|
definitionOf
|
2020-06-17 22:05:44 +04:00
|
|
|
:: ( HasLocalScope info
|
2020-06-09 15:56:11 +04:00
|
|
|
, HasRange info
|
|
|
|
)
|
|
|
|
=> Range
|
|
|
|
-> Pascal info
|
|
|
|
-> Maybe Range
|
|
|
|
definitionOf pos tree =
|
|
|
|
_sdOrigin <$> findScopedDecl pos tree
|
|
|
|
|
|
|
|
typeOf
|
2020-06-17 22:05:44 +04:00
|
|
|
:: ( HasLocalScope info
|
2020-06-09 15:56:11 +04:00
|
|
|
, HasRange info
|
|
|
|
)
|
|
|
|
=> Range
|
|
|
|
-> Pascal info
|
|
|
|
-> Maybe (Either (Pascal ()) Kind)
|
|
|
|
typeOf pos tree =
|
|
|
|
_sdType =<< findScopedDecl pos tree
|
|
|
|
|
|
|
|
implementationOf
|
2020-06-17 22:05:44 +04:00
|
|
|
:: ( HasLocalScope info
|
2020-06-09 15:56:11 +04:00
|
|
|
, HasRange info
|
|
|
|
)
|
|
|
|
=> Range
|
|
|
|
-> Pascal info
|
|
|
|
-> Maybe Range
|
|
|
|
implementationOf pos tree =
|
|
|
|
_sdBody =<< findScopedDecl pos tree
|
2020-06-10 22:37:02 +04:00
|
|
|
|
|
|
|
referencesOf
|
2020-06-17 22:05:44 +04:00
|
|
|
:: ( HasLocalScope info
|
2020-06-10 22:37:02 +04:00
|
|
|
, HasRange info
|
|
|
|
)
|
|
|
|
=> Range
|
|
|
|
-> Pascal info
|
|
|
|
-> Maybe [Range]
|
|
|
|
referencesOf pos tree =
|
|
|
|
_sdRefs <$> findScopedDecl pos tree
|