{-# LANGUAGE Strict #-}
module Apigen.Parser.Query (declName) where

import           Apigen.Parser.SymbolTable (SId, Sym)
import           Apigen.Types              (Decl (..))
import           Language.Cimple           (Lexeme)

declName :: Sym -> Maybe (Lexeme SId)
declName :: Sym -> Maybe (Lexeme SId)
declName (TypeDecl Lexeme SId
name)           = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
declName (Function Sym
_ Lexeme SId
name [Sym]
_)       = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
declName (Method Constness
_ Sym
_ Lexeme SId
name [Sym]
_)       = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
declName (Enumeration [Generated]
_ Lexeme SId
name [Sym]
_)    = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
declName (CallbackTypeDecl Lexeme SId
name [Sym]
_) = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
declName (IdTypeDecl Lexeme SId
name)         = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
declName (Define Lexeme SId
name)             = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
declName (Var Sym
_ Lexeme SId
name)              = Lexeme SId -> Maybe (Lexeme SId)
forall a. a -> Maybe a
Just Lexeme SId
name
-- ignore properties, ctors, dtors, namespaces, and classes, we don't want to namespace them further
declName Property{}                = Maybe (Lexeme SId)
forall a. Maybe a
Nothing
declName Constructor{}             = Maybe (Lexeme SId)
forall a. Maybe a
Nothing
declName Destructor{}              = Maybe (Lexeme SId)
forall a. Maybe a
Nothing
declName Namespace{}               = Maybe (Lexeme SId)
forall a. Maybe a
Nothing
declName ClassDecl{}               = Maybe (Lexeme SId)
forall a. Maybe a
Nothing
declName Sym
x                         = [Char] -> Maybe (Lexeme SId)
forall a. HasCallStack => [Char] -> a
error ([Char] -> Maybe (Lexeme SId)) -> [Char] -> Maybe (Lexeme SId)
forall a b. (a -> b) -> a -> b
$ [Char]
"unhandled in declName: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Sym -> [Char]
forall a. Show a => a -> [Char]
show Sym
x