{-# LANGUAGE OverloadedStrings #-}
module Tokstyle.Analysis.Types
( FunctionName
, NodeId
, Context
, lookupOrError
) where
import Data.Fix (Fix (..))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import Data.Set (Set)
import Data.Text (Text)
import qualified Data.Text as Text
import GHC.Stack (HasCallStack)
import qualified Language.Cimple as C
type NodeId = Int
type Context = [NodeId]
type FunctionName = Text
lookupOrError :: (Ord k, Show k) => String -> Map k a -> k -> a
lookupOrError :: String -> Map k a -> k -> a
lookupOrError String
context Map k a
m k
k = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe (String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
context String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
": Key not found in map: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ k -> String
forall a. Show a => a -> String
show k
k) (k -> Map k a -> Maybe a
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k Map k a
m)