2019-09-04 19:47:43 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass, DerivingStrategies, GeneralizedNewtypeDeriving, LambdaCase, StandaloneDeriving, FlexibleInstances, NamedFieldPuns, OverloadedStrings, QuantifiedConstraints, TypeOperators, UndecidableInstances, TypeApplications #-}
|
2019-08-27 18:27:53 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
2019-09-04 19:47:43 +03:00
|
|
|
module Instances () where
|
2019-08-27 18:27:53 +03:00
|
|
|
|
|
|
|
-- Testing code depends on certain instances that we don't want to
|
|
|
|
-- expose in semantic-core proper, yet are important enough that
|
|
|
|
-- we should keep track of them in a dedicated file.
|
|
|
|
|
|
|
|
import Analysis.ScopeGraph
|
2019-09-04 19:47:43 +03:00
|
|
|
import Control.Effect.Sum
|
2019-08-27 18:27:53 +03:00
|
|
|
import Data.Aeson
|
2019-09-04 19:47:43 +03:00
|
|
|
import qualified Data.HashMap.Strict as HashMap
|
2019-08-27 18:27:53 +03:00
|
|
|
import Data.Loc
|
2019-09-04 19:47:43 +03:00
|
|
|
import Data.Core (Core, Ann (..))
|
2019-08-27 18:27:53 +03:00
|
|
|
import qualified Data.Map as Map
|
2019-09-04 19:47:43 +03:00
|
|
|
import Data.File
|
|
|
|
import Data.Term
|
2019-08-27 18:27:53 +03:00
|
|
|
import Data.Text (Text)
|
2019-09-04 19:47:43 +03:00
|
|
|
import Data.Scope (Scope, Incr)
|
|
|
|
import qualified Data.Scope as Scope
|
|
|
|
import Data.Name
|
|
|
|
|
|
|
|
-- We default to deriving the default toEncoding definition (that piggybacks
|
|
|
|
-- off of toJSON) so that we never hit the problematic code paths associated
|
|
|
|
-- with toEncoding above.
|
|
|
|
|
|
|
|
instance ToJSON a => ToJSON (File a) where
|
|
|
|
toJSON File{fileLoc, fileBody} = object
|
|
|
|
[ "location" .= fileLoc
|
|
|
|
, "body" .= fileBody
|
|
|
|
]
|
2019-08-27 18:27:53 +03:00
|
|
|
|
|
|
|
instance ToJSON Span where
|
|
|
|
toJSON Span{spanStart, spanEnd} = object
|
|
|
|
[ "kind" .= ("span" :: Text)
|
|
|
|
, "start" .= spanStart
|
|
|
|
, "end" .= spanEnd
|
|
|
|
]
|
|
|
|
|
|
|
|
instance ToJSON Pos where
|
|
|
|
toJSON Pos{posLine, posCol} = object
|
|
|
|
[ "kind" .= ("pos" :: Text)
|
|
|
|
, "line" .= posLine
|
|
|
|
, "column" .= posCol
|
|
|
|
]
|
|
|
|
|
|
|
|
instance ToJSON Loc where
|
|
|
|
toJSON Loc{locPath, locSpan} = object
|
|
|
|
[ "kind" .= ("loc" :: Text)
|
|
|
|
, "path" .= locPath
|
|
|
|
, "span" .= locSpan
|
|
|
|
]
|
|
|
|
|
|
|
|
instance ToJSON Ref where
|
|
|
|
toJSON (Ref loc) = object [ "kind" .= ("ref" :: Text)
|
|
|
|
, "location" .= loc]
|
|
|
|
|
|
|
|
instance ToJSON Decl where
|
|
|
|
toJSON Decl{declSymbol, declLoc} = object
|
|
|
|
[ "kind" .= ("decl" :: Text)
|
|
|
|
, "symbol" .= declSymbol
|
|
|
|
, "location" .= declLoc
|
|
|
|
]
|
|
|
|
|
|
|
|
instance ToJSON ScopeGraph where
|
|
|
|
toJSON (ScopeGraph sc) = toJSON . Map.mapKeys declSymbol $ sc
|