1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
module Data.GI.GIR.Method
( Method(..)
, MethodType(..)
, parseMethod
) where
import Data.Text (Text)
import Data.GI.GIR.Arg (Arg, parseArg)
import Data.GI.GIR.Callable (Callable(..), parseCallable)
import Data.GI.GIR.Parser
data MethodType = Constructor -- ^ Constructs an instance of the parent type
| MemberFunction -- ^ A function in the namespace
| OrdinaryMethod -- ^ A function taking the parent
-- instance as first argument.
deriving (Eq, Show)
data Method = Method {
methodName :: Name,
-- | The symbol in the dynlib that this method refers to.
methodSymbol :: Text,
methodType :: MethodType,
methodMovedTo :: Maybe Text,
methodCallable :: Callable
} deriving (Eq, Show)
parseInstanceArg :: Parser Arg
parseInstanceArg = do
instanceInfo <- parseChildrenWithLocalName "parameters" parseInstPars
case instanceInfo of
[[inst]] -> return inst
[] -> parseError $ "No instance-parameter found."
_ -> parseError $ "Too many instance parameters."
where parseInstPars :: Parser [Arg]
parseInstPars = parseChildrenWithLocalName "instance-parameter" parseArg
parseMethod :: MethodType -> Parser Method
parseMethod mType = do
name <- parseName
shadows <- queryAttr "shadows"
let exposedName = case shadows of
Just n -> name {name = n}
Nothing -> name
callable <- if mType /= OrdinaryMethod
then parseCallable
else do
c <- parseCallable
instanceArg <- parseInstanceArg
return $ c {args = instanceArg : args c}
symbol <- getAttrWithNamespace CGIRNS "identifier"
movedTo <- queryAttr "moved-to"
return $ Method {
methodName = exposedName
, methodSymbol = symbol
, methodType = mType
, methodMovedTo = movedTo
, methodCallable = callable
}
|