{-# LANGUAGE DefaultSignatures #-}

module Language.Fortran.AST.Annotated where

import Language.Fortran.Util.FirstParameter

-- Retrieving SrcSpan and Annotation from nodes
class Annotated f where
  getAnnotation :: f a -> a
  setAnnotation :: a -> f a -> f a
  modifyAnnotation :: (a -> a) -> f a -> f a
  default getAnnotation :: (FirstParameter (f a) a) => f a -> a
  getAnnotation = forall a e. FirstParameter a e => a -> e
getFirstParameter

  default setAnnotation :: (FirstParameter (f a) a) => a -> f a -> f a
  setAnnotation = forall a e. FirstParameter a e => e -> a -> a
setFirstParameter

  modifyAnnotation a -> a
f f a
x = forall (f :: * -> *) a. Annotated f => a -> f a -> f a
setAnnotation (a -> a
f (forall (f :: * -> *) a. Annotated f => f a -> a
getAnnotation f a
x)) f a
x